PushViewController 没有推送

发布于 2024-12-21 22:10:13 字数 1174 浏览 5 评论 0原文

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

它没有给出任何错误。您认为这是导航控制的问题吗?为了测试,我在此视图上添加了一个按钮并且它可以工作;当我单击它时,它确实会推送到下一个视图。

- (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];
}

好吧,我想我已经找到原因了;但不知道如何解决它。

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

我希望表格成为子视图,因为我想在表格上方放置图像。所以,我认为这里的问题是这一行:

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

它没有引用视图中的表。谁能告诉我如何修改它以便它引用视图中的表?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

提笔落墨 2024-12-28 22:10:13

如果 didSelectRow... 没有被调用,那么您的视图控制器可能没有设置为表视图的委托。

这是在使用 UITableViewController 时自动为您设置的,但在使用标准视图控制器时必须显式执行此操作。

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.

痞味浪人 2024-12-28 22:10:13

您的问题的答案通常是 self.navigationController 实际上是 nil 因为您的视图没有导航控制器。您可能需要获取指向项目导航控制器的指针并将视图推送到其上。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文