我在当前项目中使用了两张UIAction表。我可以让一个人工作得很好但是当我插入第二个动作表时,它会运行与第一个相同的争论。我如何单独定义动作表?
-(IBAction) phoneButtonClicked:(id)sender
{
// open a dialog with just an OK button
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:[NSString stringWithFormat:@"Phone: %@",phone],nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view]; // show from our table view (pops up in the middle of the table)
[actionSheet release];
}
-(IBAction) mapButtonClicked:(id)sender
{
// open a dialog with just an OK button
UIActionSheet *mapActionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:self cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:[NSString stringWithFormat:@"Map"],nil];
mapActionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[mapActionSheet showInView:self.view]; // show from our table view (pops up in the middle of the table)
[mapActionSheet release];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex == 0){
NSString *callPhone = [NSString stringWithFormat:@"tel:%@",phone];
NSLog(@"Calling: %@", callPhone);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
}
}
答案 0 :(得分:3)
UIActionSheet
是UIView
的子视图,因此您可以使用tag
属性。
答案 1 :(得分:0)
制作actionSheets实例变量并在委托方法中测试返回的操作表。
或者,编写自己的UIActionSheet
(和UIAlert
的子类,它会遭受同样的烦恼),在捕获返回时将回调发送给委托对象。