如何将seque ios5 storyboard uitableview中的数据传递给详细视图

Cat*_*ber 25 iphone uitableview ios5

我正在使用故事板在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;    
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助.

M. *_*edi 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,并在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];
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 这个答案需要被认为是正确的. (3认同)

小智 12

我遇到了同样的问题,遵循Ray Wenderlich教程的部分内容,发现你需要选择表格单元格并按Ctrl键拖动到你的viewcontroller.然后调用 performSegueWithIdentifierdidSelectRowAtINdexPath.

- (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;
        }   
}
Run Code Online (Sandbox Code Playgroud)


mor*_*ler 0

我遇到了同样的问题,但还没有用故事板解决它。但是,我认为 Segue 应该从单元格开始,而不是整个 tableviewcontroller。如果您使用原型单元,这可能会起作用 - 但我不知道代码创建的单元类型。也将不胜感激有关此主题的任何帮助。

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