我UIAlertView在同一个视图控制器中有两个s,我想使用委托方法
-(void)alertView:(UIAlertView *?alertView clickedButtonAtIndex:(NSInteger) buttonIndex
Run Code Online (Sandbox Code Playgroud)
按下警报视图中的按钮时将调用此方法.但是,两个警报视图都将调用相同的方法.
如何区分两个警报视图?
tag显示警报时,将属性设置为不同的值.它只是一个整数,可以在callback/delegate方法中查询.
这是一个例子(使用ActionSheet而不是AlertView,但原理完全相同):
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Some option", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
actionSheet.tag = 10;
[actionSheet showInView:self.view];
[actionSheet release];
Run Code Online (Sandbox Code Playgroud)
然后在你的选择器中:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (actionSheet.tag) {
case 10:
// do stuff
break;
case 20:
// do other stuff
break;
}
}
Run Code Online (Sandbox Code Playgroud)
当然,你使用常量而不是文字值,本地化字符串等,但这是基本的想法.
| 归档时间: |
|
| 查看次数: |
3200 次 |
| 最近记录: |