iPhone,是否可以将actionSheet和ClickedButtonIndex事件放入可重用类中?
我想在多个视图的iPhone,是否可以将actionSheet和ClickedButtonIndex事件放入可重用类中?,iphone,objective-c,xcode,Iphone,Objective C,Xcode,我想在多个视图的ClickedButtonIndex中提供相同的按钮和功能,我可以在可重用类中这样做吗 如果是这样,如何实现?一种方法是将actionsheet+委托封装到一个新类中: @interface MyActionSheet : NSObject <UIActionSheetDelegate> { UIActionSheet* _actionSheet; } @end @implementation MyActionSheet - (id) initAndSh
ClickedButtonIndex
中提供相同的按钮和功能,我可以在可重用类中这样做吗
如果是这样,如何实现?一种方法是将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
@接口MyActionSheet:NSObject
{
UIActionSheet*\U actionSheet;
}
@结束
@实施我的行动表
-(id)initAndShowInView:(UIView*)视图
{
if((self=[super init]))
{
_actionSheet=[[UIActionSheet alloc]initWithTitle:@“你好”委托:自取消按钮:@“完成”销毁按钮:无其他按钮:@“按钮1”,“按钮2”,无];
[_actionsheetshowinview:view];
}
回归自我;
}
-(无效)操作表:(UIActionSheet*)操作表单击按钮索引:(NSInteger)按钮索引
{
//你的逻辑在这里
}
-(无效)解除锁定{
[_行动单发布];
[super dealoc];
}
@结束
可以对此进行扩展,以添加可能需要的委托方法。您需要确保在操作表可见时对象继续存在(保留在其上)-操作表不会增加其委托上的引用计数