我想將視圖控制器中的變量傳遞給另一個視圖控制器,以便當用戶在第一個表視圖中選擇某一行時,應用程序將把他帶到另一個視圖控制器,其中將顯示所選項目的詳細信息。 這是我的代碼:如何使用didSelectRowAtIndexPath將變量從uitableview傳遞給第二個tableview?
- (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是,我希望存儲選定行的內容的全局變量。 任何幫助將不勝感激。
by'dv.selectedAuthors = selectedAuthors;''你已經將數據傳遞給第二個視圖控制器。您應該在詳細信息視圖控制器中顯示基於selectedAuthors的詳細信息。 – Moxy 2012-08-10 01:56:24
請檢查鏈接它會顯示您的具體問題:http://stackoverflow.com/questions/11897149/how-to-send-the-details-of-a-selected-cell-to-another-view-controller – 2012-08-10 07:26:39