我有以下语句从 json 提要填充表。从表中选择一行后,它会传回原始控制器,以便再次查询 api 以填充一些字段。
问题是传回的值与已选择的单元格无关。
这是我的代码。
在详细视图控制器中
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
NSDictionary *addressdict = [jsonData objectAtIndex:indexPath.row];
NSString *address = [addressdict objectForKey:@"StreetAddress"];
idnumber = [addressdict objectForKey:@"Id"];
cell.textLabel.text = address;
cell.detailTextLabel.text = idnumber;
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"sendAddress"])
{
// Get reference to the destination view controller
SignUpViewController *controller = (SignUpViewController *)segue.destinationViewController;
// Pass any objects to the view controller here, like...
controller->idnumber = idnumber;
}
}
在我的主视图控制器中,我这样做
NSLog(@"The Address ID is: %@",idnumber);
但它返回的值是不正确的。
任何人都可以帮忙吗?