pushViewController没有推送 [英] pushViewController is not pushing

查看:85
本文介绍了pushViewController没有推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用initWithNibName将单元格推送到详细视图,但是我想使用单个情节提要,而不是拥有大量笔尖文件.单击下面的代码应该在单击单元格时将视图推送到subcategoriesViewController.单元格是根据json数据动态生成的.

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.

此控制器中的tableview实际上是viewController的子视图.我复制了这些文件,并创建了一个新的视图,即TableViewController.此代码在TableViewController中使用时可完成此工作,但在表视图为ViewController子视图的控制器中使用时,则不会执行此操作.

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?

推荐答案

如果未调用didSelectRow...,则可能未将视图控制器设置为表视图的委托.

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

这是使用UITableViewController时自动为您设置的,但是在使用标准视图控制器时必须显式地进行设置.

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

这篇关于pushViewController没有推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆