2010-11-11 30 views

回答

1

一種方法是封裝你actionsheet +委託到一個新的類:

@interface MyActionSheet : NSObject <UIActionSheetDelegate> 
{ 
    UIActionSheet* _actionSheet; 
} 

@end 

@implementation MyActionSheet 

- (id) initAndShowInView: (UIView*) view 
{ 
    if ((self = [super init])) 
    { 
     _actionSheet = [[UIActionSheet alloc] initWithTitle: @"Hi There" delegate:self cancelButtonTitle:@"done" destructiveButtonTitle: nil otherButtonTitles: @"button 1", @"button2", nil]; 
     [_actionSheet showInView:view]; 
    } 

    return self; 
} 

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    // your logic here 
} 

- (void)dealloc { 

    [_actionSheet release]; 

    [super dealloc]; 
} 

@end 

這可以擴展到加你可能需要委託方法。您需要確保對象繼續存在(在其上保留保留),而操作單可見 - 操作單不會增加其代表的參考計數...

相關問題