[英]How pass data in seque ios5 storyboard uitableview to detail view
我正在使用故事板在ios5中創建一個應用程序。 我有一個嵌入在導航控制器中的tableviewcontroller,當你點擊tableviewcontroller中的單元格時,應該將有關該單元格主題的一些細節傳遞給詳細視圖。 我使用plist來填充tableview和詳細視圖。 我沒有使用故事板就做到了這一點,但想學習如何使用故事板。 我有seque從tableviewcontroller轉到我的詳細視圖。
我的seque代碼是:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"DetailViewControllerSeque"])
{ DetailViewController *detailViewController = [segue destinationViewController];
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"questList.plist"];
NSArray *tempArray = [finalPath valueForKey:@"description"];
NSString *descriptionString = [tempArray valueForKey:@"description"];
detailViewController.detailDescriptionText.text = descriptionString;
}
}
謝謝你的幫助。
我遇到了同樣的問題(由於缺乏iOS5的經驗)。
事實證明,這是一個iOS5 SDK的示例應用程序,它有一個表格視圖,在點擊表格單元格時使用segues:“Simple Drill Down”。
您可以在表格單元格中設置segue,並在storyboard文件中為其指定名稱。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
/*
When a row is selected, the segue creates the detail view controller as the destination.
Set the detail view controller's detail item to the item associated with the selected row.
*/
if ([[segue identifier] isEqualToString:@"ShowSelectedPlay"]) {
NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
DetailViewController *detailViewController = [segue destinationViewController];
detailViewController.play = [dataController objectInListAtIndex:selectedRowIndex.row];
}
}
我遇到了同樣的問題,遵循Ray Wenderlich教程的部分內容,發現你需要選擇表格單元格並按Ctrl鍵拖動到你的viewcontroller。 然后在didSelectRowAtINdexPath
調用performSegueWithIdentifier
。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"mySegueId" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSLog(@"prepareForSegue: %@", segue.identifier );
if ([segue.identifier isEqualToString:@"mySegueId"])
{
DetailController *detailController = segue.destinationViewController;
detailController.delegate = (id)self;
detailController.selected = selectedRow;
}
}
不需要打電話: [self performSegueWithIdentifier:@"mySegueId" sender:self];
你可以使用NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
獲取您選擇的信息,在您的- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{...}
函數中。
試試這種方式
名字你的segue(從tableview單元格到詳細視圖)。然后
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"yourSegueName"]){
DetailViewController * detailViewController =segue.destinationViewController;
detailViewController =[self.yourTableViewDataArray objectAtIndex:[self.yourTableView indexPathForSelectedRow].row];
}
}
不要忘記導入SecondViewController / DetailViewController
我遇到了同樣的問題,還沒有通過故事板解決它。 但是,我認為segue應該從單元格開始,而不是整個tableviewcontroller。 如果您使用原型單元格,這可能會起作用 - 但我不知道代碼創建的單元格類型。 我也非常感謝這個主題的任何幫助。
編輯: http ://kurrytran.blogspot.com/2011/10/ios-5-storyboard-and.html上的教程表明不存在segue解決方案,您仍然需要在代碼中轉換到詳細信息視圖。 我不知道這是多么正確,但我會這樣做,直到有人向我展示純粹的故事板/ segue解決方案;)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.