无法从数组中获取indexPath.row(错误indexPath未声明)?
我在我的 .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 显示它
,如果我选择单元格,
它将弹出一个带有文本字段的警报视图,它可以重命名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???
I declared a NSArray in my .h
@interface DevicePreferencesController : UITableViewController < UIAlertViewDelegate >{
NSArray *plist;
UITextField *deviceName;
}
This array is use to load a plist data from URL
and this is the plist I got
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;
}
)
I show It by a tableView
and if I selected the cell
It will pop up an alertView with a textField,it can rename the data in the plist
And here is the button action for 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];
}
}
}
But I got error here "indexPath" undeclared !
Why ? plist is an array ,why can't I get indexPath from an array ???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
'indexPath' 不是您的变量,所以这是因为它未声明。您应该将 tableview didselectedrow 方法中的 indexPath 存储到本地变量,并在alertView委托方法中使用它。
'indexPath' is not your variable, so that is because it's undeclared. You should store the indexPath in the tableview didselectedrow method, to a local variable, and use it in the alertView delegate method.
indexPath 可作为 TableView 的 Delegate 和 DataSource 方法的一部分使用。您的类中是否有一个名为 indexPath 的变量作为全局变量或成员变量?
indexPath is available as part of TableView's Delegate and DataSource methods. Do you have a variable named indexPath as a global variable or as a memeber variable in your class?