0
我想在幾個視圖中提供相同的按鈕和clickedButtonAtIndex
中的相同功能,我可以在可重用類中執行此操作嗎?iPhone,是否可以將actionSheet和clickedButtonAtIndex事件放入可重用類中?
如果是的話怎麼樣?
我想在幾個視圖中提供相同的按鈕和clickedButtonAtIndex
中的相同功能,我可以在可重用類中執行此操作嗎?iPhone,是否可以將actionSheet和clickedButtonAtIndex事件放入可重用類中?
如果是的話怎麼樣?
一種方法是封裝你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
這可以擴展到加你可能需要委託方法。您需要確保對象繼續存在(在其上保留保留),而操作單可見 - 操作單不會增加其代表的參考計數...