pushViewController is not pushing

旧巷老猫 提交于 2019-12-13 05:19:28

问题


I was using initWithNibName to push the cells to detail views but I want to use single storyboard rather than having numerous nib files. The below code is supposed to push the view to subcategoriesViewController when the cell is clicked. the cells are dynamic from json data.

Its not giving any errors. Do you think its an issue with navigation control? Just to test, I added a button on this view and it works; when I click it, it does push to next view.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dict = [rows objectAtIndex: indexPath.row];


    subcategoriesViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"subcategoriesViewController"];
    controller.CATNAME = [dict objectForKey:@"C_NAME"];
    controller.CATNUMBER = [dict objectForKey:@"CAT_ID"];
    [self.navigationController pushViewController:controller animated:YES];
//    [controller release];
}

Okay I think I have found the cause; but don't know how to fix it.

The tableview in this controller is actually a subview of a viewController. I duplicated these files and created a new view which is a TableViewController. This code, when used in the TableViewController does the job, but it doesn't do it when used in a controller where the tableview is a subview of a ViewController.

I want the table to be a subview because I want to put an image above the table. So, I think the problem here is this line:

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

It does not reference the table in the view. Can anyone tell me how to modify this so it would reference the table within the view?


回答1:


If didSelectRow... is not being called then your view controller is probably not set as the delegate of your table view.

This is set up for you automatically when using a UITableViewController but you have to explicitly do it when using a standard view controller.




回答2:


An answer to your problem is often that self.navigationController is in fact nil because there is no navigation controller for your view. You perhaps have to get a pointer to the navigation controller of your projet and push your view on it.



来源:https://stackoverflow.com/questions/8552531/pushviewcontroller-is-not-pushing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!