使用didSelectRowAtIndexPath调用detailview

时间:2013-12-23 07:26:54

标签: ios iphone uitableview

我的viewcontroller正在使用UITableView,我想通过点击该行转到detialView。使用didSelectRowAtIndexPath

我正在使用故事板,但我的UITableView课程没有使用stroyborad上的“场景”,而是以detailView为其他课程Storyboard

但是我无法展示我的detailView,尝试了很多想法。在此我无法使用segue,因为UItableview类不是以编程方式制作的场景,另一种显示detialViewController的方式是使用didSelectRowAtIndexPath

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    ServiceDisplayViewController *serviceDisplayViewController =
    [self.storyboard instantiateViewControllerWithIdentifier:@"serviceDisplayViewController"];

    [self presentViewController:serviceDisplayViewController animated:NO completion:nil];


}

但它给了我错误。

Application tried to present a nil modal view controller on target <SegmentsViewController: 0xa8757e0>.'

任何人都可以建议我解决此问题的最佳方法。

提前致谢。

3 个答案:

答案 0 :(得分:0)

ServiceDisplayViewController *serviceDisplayViewController =
[self.storyboard instantiateViewControllerWithIdentifier:@"ServiceDisplayViewController"];
Your Identifier should be your class name not object name

答案 1 :(得分:0)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    //This is the line where your error is
    ServiceDisplayViewController *serviceDisplayViewController =
    [self.storyboard instantiateViewControllerWithIdentifier:@"serviceDisplayViewController"];
    //serviceDisplayViewController object does not get the correct object.
   // In the storyboard check whether the identifier name(serviceDisplayViewController) is correct or not. Check even for case-sensitive error
   //Also check self.storyboard object is also not nil



    [self presentViewController:serviceDisplayViewController animated:NO completion:nil];


}

enter image description here

答案 2 :(得分:0)

首先确保标识符正确无误。然后写下面的代码

UIStoryboard *mystoryboard = [UIStoryboard storyboardWithName:@"myStoryBoardName" bundle:nil];

if (mystoryboard != nil)
{
  ServiceDisplayViewController *serviceDisplayViewController = [mystoryboard instantiateViewControllerWithIdentifier:@"ServiceDisplayViewController"];

    if(serviceDisplayViewController != nil)
    {
      [self presentViewController:serviceDisplayViewController animated:NO completion:nil];
    }
    else
    {
       NSLog(@"%@", serviceDisplayViewController is returning as nil);
    }
}
else
{
   NSLog(@"%@", mystoryboard is returning as nil);  
}