简体   繁体   中英

call detailview by using didSelectRowAtIndexPath

My viewcontroller is using UITableView and i want to go to detialView by clicking on the row. Using the didSelectRowAtIndexPath .

I am working on storyboard but my UITableView class is not using Scene on stroyborad it made programatically and other class with is detailView with is a scene on the Storyboard .

But i'm unable to show my detailView , Trying so many ideas. In this i'm unable to use segue because UItableview Class is not a scene it made programtically and the other way to display detialViewController is using didSelectRowAtIndexPath .

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

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

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


}

But it gives me error.

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

Can anyone please suggest me the best way to resolve this issue.

Thanks In Advance.

ServiceDisplayViewController *serviceDisplayViewController =
[self.storyboard instantiateViewControllerWithIdentifier:@"ServiceDisplayViewController"];
Your Identifier should be your class name not object name
- (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];


}

在此处输入图片说明

First make sure the identifiers are correct. then write the below code

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM