Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UITableView和alertView:ClickedButtonIndex方法_Iphone_Objective C - Fatal编程技术网

Iphone UITableView和alertView:ClickedButtonIndex方法

Iphone UITableView和alertView:ClickedButtonIndex方法,iphone,objective-c,Iphone,Objective C,我正在玩xCode,并试图创建一个小应用程序,其中包含一个表视图(使用数组构建),其中包含各种个人的姓名。用户可以单击表视图中的一行,并显示一个UIAlert,其中包含呼叫此人或取消的选项 如果他们单击“取消”,UIalert将解除。如果他们点击呼叫按钮,我想启动电话应用程序并拨打他们的电话号码 以下是迄今为止我所掌握的代码: //Generate the UIAlert when the user clicks on a row - (void)tableView:(UITableView *

我正在玩xCode,并试图创建一个小应用程序,其中包含一个表视图(使用数组构建),其中包含各种个人的姓名。用户可以单击表视图中的一行,并显示一个UIAlert,其中包含呼叫此人或取消的选项

如果他们单击“取消”,UIalert将解除。如果他们点击呼叫按钮,我想启动电话应用程序并拨打他们的电话号码

以下是迄今为止我所掌握的代码:

//Generate the UIAlert when the user clicks on a row
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexpath
{
    NSUInteger row = [indexpath row];
    NSString *rowValue = [listData objectAtIndex:row];

    NSString *message = [[NSString alloc] initWithFormat:@"Contact %@", rowValue];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Call this Office"
                                                    message:message
                                                    delegate:self
                                                    cancelButtonTitle:@"Cancel"
                                          otherButtonTitles:@"Call",nil];   


    [alert show];
    [message release];
    [alert release];
}

//Detect which of the UIAlert buttons was clicked and dial a different number
//based on the index of the original row that was selected
- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex 
{

    switch (row) 
    {
        case 1:         
            if (buttonIndex != [alert cancelButtonIndex]) 
            {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://123456789"]];
            }
            break;

        case 2:         
            if (buttonIndex != [alert cancelButtonIndex]) 
            {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://987654321"]];
            }
            break;

        default:
            break;
    }


}

这里是我的问题-我知道我上面的switch语句不起作用-该方法不知道“row”是什么。那么,我如何准确地传入/访问用户点击用于我的switch语句的行的索引呢?

当您在说[alert show]设置其标记之前创建UIAlertView时

alert.tag = [indexPath row];
现在在switch(row)语句中

switch(alert.tag)

当您在说[alert show]之前创建UIAlertView时,请设置其标记

alert.tag = [indexPath row];
现在在switch(row)语句中

switch(alert.tag)

哦,天哪!我甚至没想过要这么做。谢谢davydotcom的留言。非常感谢!哦,天哪!我甚至没想过要这么做。谢谢davydotcom的留言。非常感谢!