2011-10-29 16 views
25

我正在使用storyboards在ios5中创建应用程序。我有一个嵌入在导航控制器中的tableviewcontroller,当您单击tableviewcontroller中的单元格时,应该将有关该单元格主题的一些细节传递给详细视图。我使用plist来填充tableview和detail视图。我没有使用故事板而是做得很好,但想要学习如何使用故事板。我有seque从tableviewcontroller去我的详细信息视图。如何通过seque ios5 storyboard uitableview中的数据传递详细信息

我对塞克代码:

- (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;  
    } 
} 

感谢您的帮助。

+4

什么是你的问题? –

回答

0

我得到了同样的问题,还没有解决它与故事板。但是,我认为segue应该从单元格开始,而不是整个tableviewcontroller。如果您使用原型单元格,这可以工作 - 但我不知道代码创建的单元格类型。也希望对这个主题有任何帮助。

编辑: 在http://kurrytran.blogspot.com/2011/10/ios-5-storyboard-and.html的教程建议,不存在segue解决方案,您仍然必须转换到代码中的详细视图。我不知道这是多么正确,但我会这样做,直到有人向我展示纯故事板/赛格解决方案;)。

12

我得到了同样的问题,随后Ray Wenderlich教程的一部分,发现你需要选择表格单元格和Ctrl-Drag到你的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; 
     } 
} 
+0

谢谢,这正是我想要的!这里有一个错误detailControllerController,不会让我编辑或我自己修复它。 –

+0

谢谢你,伙计。 – SampathKumar

+0

这两个答案帮助我,但我很惊讶,我也需要这一个。我认为苹果公司会这样实施,它将足以将细胞与下一个场景连接起来,而不必告诉哪个阶段执行......无论如何,它的工作原理。 – Heckscheibe

67

我有同样的问题(缺乏与iOS5的经验)。

事实证明,这是一个iOS5 SDK的示例应用程序,它有一个表格视图,当表格单元格被点击时使用segues:“Simple Drill Down”。

https://web.archive.org/web/20130513140140/http://developer.apple.com:80/library/ios/#samplecode/SimpleDrillDown/Introduction/Intro.html

你设定在表格单元格的SEGUE,并给它在故事板文件的名称。

- (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]; 
    } 
} 
+0

谢谢你这个辉煌的答案! (+1) – filou

+0

非常感谢。一直坚持了几个小时。谢谢! – Patrick

+3

这个答案需要被接受为正确的。 – dbarros

1

不需要召唤: [self performSegueWithIdentifier:@"mySegueId" sender:self];

你可以使用NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];让你选择的信息,在你的- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{...}功能。

0

尝试这种方式

名字你赛格瑞(从实现代码如下细胞详细视图)。然后

-(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

相关问题