0

我在我的 .h 中声明了一个 NSArray

@interface DevicePreferencesController : UITableViewController < UIAlertViewDelegate >{
    NSArray *plist;
    UITextField *deviceName;
}

该数组用于从 URL 加载 plist 数据

这是我得到的plist

plist:(
        {
        category = 11;
        id = 1;
        name = light1;
    },
        {
        category = 11;
        id = 5;
        name = window;
    },
        {
        category = 12;
        id = 2;
        name = dimmer2;
    },
        {
        category = 23;
        id = 3;
        name = win;
    }
)

我通过 tableView 显示它

如果我选择了单元格

它会弹出一个带有textField的alertView,它可以重命名plist中的数据

这是 alertView 的按钮操作

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if ([alertView tag]==1) {
        if (buttonIndex == 1){
            [request setPostValue:[[self.plist objectAtIndex:indexPath.row] valueForKey:@"id"]  forKey:@"id"];
            [request setPostValue:deviceName.text  forKey:@"name"];
            [request startSynchronous];
        }
    }
}

但是我在这里遇到错误“indexPath”未声明

为什么 ?plist 是一个数组,为什么我不能从数组中获取 indexPath ???

4

2 回答 2

2

'indexPath' 不是你的变量,所以那是因为它没有声明。您应该将 tableview didselectedrow 方法中的 indexPath 存储到局部变量中,并在 alertView 委托方法中使用它。

于 2010-11-24T10:11:28.963 回答
1

indexPath 作为 TableView 的 Delegate 和 DataSource 方法的一部分提供。您有一个名为 indexPath 的变量作为全局变量还是类中的成员变量?

于 2010-11-24T10:13:27.783 回答