简体   繁体   中英

detailview screen can not open with pushViewController in a tableview

I have a tabbar in my project and each tab bar has a tableview. I want to open a detail screen when click a row in a tableview as follows. But nothing happens. Where's the mistake I'm doing. How should I set up a logic.

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
DetailScreen *detail = [[DetailScreen alloc] initWithNibName:@"DetailScreen" bundle:nil];
 [self.navigationController pushViewController:detail animated:YES];
[detail release];

}

There are many possible reasons nothing is happening when you click on a cell.

  • Put a break point in this method. Is It even being called?
  • After the App has stopped at the breakpoint, go to the console type po detail after the instance is initialised. Make sure it's not (null)
  • Also try typing po [self navigationController] to check whether the navigation controller exists.

You've probably not got a navigation controller. How are you creating the tabbarcontroller? in interface builder or through code in the AppDelegate's didFinishLaunchingWithOptions: method?

Have you done this?

    YourViewController *yourVC = [[YourViewController alloc] initWithNibName:@"YourViewController" bundle:nil];

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:yourVC];

    self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController, nil];

try this,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
     DetailScreen *detail = [[DetailScreen alloc] init];
     [self.navigationController pushViewController:detail animated:YES];
     [detail release];
}

I guess you don't have a navigation controller so

[self.navigationController pushViewController:detail animated:YES];

will not work.

use

[self.view addSubview:detail.view]

or

[self presentModalViewController:detail animated:YES];

instead

如果你的项目是基于UITabBarViewController的应用程序,我不认为你可以使用pushViewController导航到另一个视图,除非你的项目中有navigationController

Add your view controller(your table view containing controller) into navigation controller and then start using

DetailScreen *detail = [[DetailScreen alloc] initWithNibName:@"DetailScreen" bundle:nil];
    [self.navigationController pushViewController:detail animated:YES];
[self.navigationController pushViewController:detail animated:YES];

而是将您的详细推送代码移动到另一个方法并调用:

[self performSelector:@selector(myMethod:) withObject: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