在用户单击操作表中的“destructButton”之后,我实现了一个警报视图。代码片段如下:
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex != actionSheet.cancelButtonIndex)
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Something happened!"
message:nil
delegate:nil
cancelButtonTitle:@"Phew!"
otherButtonTitles:nil];
}
[alert show];
[alert release];
}我已经在.h文件中包含了UIActionSheetDelegate协议
@interface Control_FunViewController : UIViewController <UIActionSheetDelegate> {
UITextField *nameField;
UITextField *numberField;
UILabel *sliderLabel;
UISwitch *leftSwitch;
UISwitch *rightSwitch;
UIButton *doSomethingButton;
}但是,当我单击操作表中的destructButton时,什么也没有发生。我是不是漏掉了什么?
谢谢
真
发布于 2011-04-05 13:42:23
您的代表需要实现 actionSheet:clickedButtonAtIndex:**.**
行动说明书将在actionSheet:clickedButtonAtIndex:之后解散,之后代表将收到actionSheet:didDismissWithButtonIndex:。
来自Apple Action Sheet Delegate Protocol reference
...代理必须实现actionSheet:clickedButtonAtIndex:消息,以便在单击这些按钮时进行响应;否则,您的自定义按钮什么也不做。在调用actionSheet:clickedButtonAtIndex:委托方法后,操作表将自动关闭。
您可以查看使用UIActionSheet的示例项目,如GenericKeychain:
// Action sheet delegate method.
- (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex
{
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0)
{
[passwordItem resetKeychainItem];
[accountNumberItem resetKeychainItem];
[self.tableView reloadData];
}
}发布于 2011-04-05 18:10:40
您已在.h文件上添加了UIActionSheetDelegate。这不仅仅是足够的。您还必须为UIActionSheet对象设置委托。请参阅下面的编码:
-(空)showActionSheet{ UIActionSheet *showActionSheet =[UIActionSheet allocinitWithTitle:@"dsfs“委托:自取消按钮标题:@”First Btn“destructiveButtonTitle:@"Dest Btn”otherButtonTitles:nil];action showInView:self.view;
}
在代码中,我将UIActionSheet委托设置为self,如果您在ViewController (Control_FunViewController)上添加了此方法,则此方法有效。
https://stackoverflow.com/questions/5547561
复制相似问题