我想将变量从视图控制器传递到另一个视图控制器,这样当用户在第一个表视图中选择某一行时,应用程序会将他带到另一个视图控制器,其中将显示所选项目的详细信息。这是我的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedAuthors = [theauthors objectAtIndex:indexPath.row];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
Details *dvController = [storyboard instantiateViewControllerWithIdentifier:@"Details"]; //Or whatever identifier you have defined in your storyboard
dvController.selectedAuthors = selectedAuthors;
UIAlertView *messageAlert = [[UIAlertView alloc]
initWithTitle:@"Row Selected" message:authorNAme delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
// Display Alert Message
authorNAme = [[NSString stringWithFormat:[theauthors objectAtIndex:indexPath.row]] intValue];
[messageAlert show];
[self.navigationController pushViewController:dvController animated:YES];
}
selectedAuthors 是一个字符串 authorName 是一个全局变量,我想在其中存储所选行的内容。任何帮助将不胜感激。