2010-03-11 1 views
20

는이 코드가 있습니다기존 UIActionSheet에 버튼을 추가하는 방법은 무엇입니까?

UIActionSheet *actionSheet = [[[UIActionSheet alloc] 
       initWithTitle:@"Illustrations" 
       delegate:self 
       cancelButtonTitle:@"Cancel" 
       destructiveButtonTitle:nil 
       otherButtonTitles: @"ABC", @"XYZ", 
       nil] autorelease]; 
UIImage *image = // whatever, snip 
if (image != nil) 
{ 
    [actionSheet addButtonWithTitle:@"LMNOP"]; 
} 

을하며 조건 내 LMNOP 버튼을 추가하는 훌륭한 일을한다.

... 취소 버튼 이후.

조건부 단추로 작업 시트를 구성하려면 어떻게해야합니까? 슬프게도, 나는 할 수 없습니다

UIActionSheet *actionSheet = [[[UIActionSheet alloc] 
     // ... etc. 
     otherButtonTitles: someMutableArray 
     // ... etc. 

을 그 확실히 도움이 때문이다.

아이디어가 있으십니까?

감사합니다.

답변

53

init 메소드 뒤에 모든 버튼을 추가 할 수 있습니다.

UIActionSheet* sheet = [[[UIActionSheet alloc] init] autorelease]; 
sheet.title = @"Illustrations"; 
sheet.delegate = self; 
[sheet addButtonWithTitle:@"ABC"]; 
[sheet addButtonWithTitle:@"XYZ"]; 
if (condition) 
    [sheet addButtonWithTitle:@"LMNOP"]; 
sheet.cancelButtonIndex = [sheet addButtonWithTitle:@"Cancel"]; 
+3

아하! sheet.cancelButtonIndex = ... 부분을 놓쳤습니다. 그것이 내가 그림을 완성하는 데 필요한 것입니다. 감사합니다. – Olie

+0

'sheet.destructiveButtonIndex'와 함께 작동합니다. – zekel

-4

im는 iOS 4에서 코딩하는 방식이며 사용되는 방법입니다. 버튼에 대한 제목을 otherbutton 섹션에 추가하기 만하면됩니다.

UIActionSheet *phoneActionSheet = [[UIActionSheet alloc] 
              initWithTitle:@"Do you want to call or text this person?" 
              delegate:self 
              cancelButtonTitle:@"Cancel" 
              destructiveButtonTitle:@"Call"            
              otherButtonTitles:@"Text",nil];