我有设置 UIAlertView 的代码:
-(IBAction)showMessage
{
//NSInteger *buttonIndex = NULL;
UIAlertView *message = [[UIAlertView alloc] initWithTitle:nil
message:nil
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Email",@"SMS",@"Facebook",@"Twitter", nil];
[message show];
}
以及解释用户做出选择后要做什么的代码:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1){
[self openMail];
}
else if (buttonIndex == 2)
//etc.
}
但我不知道如何将两者联系起来。alertView: clickedButtonAtIndex
显而易见的答案是在调用的第一段代码中添加一行UIAlertView *message
,但是如何分配buttonIndex
呢?你如何alertView
判断用户是否选择了 Facebook、Email 等?