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:@开发者_JAVA技巧"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 ???
'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 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?
精彩评论