【问题标题】:uitableView didSelectRowAtIndexPath "selected row not loading the detail view"uitableView didSelectRowAtIndexPath “选定行未加载详细视图”
【发布时间】:2013-10-10 12:36:51
【问题描述】:

我有一个 7 行的表格视图,我想点击我的行并加载 detailView(uiViewController)

我可以选择行,我可以看到登录控制台,但它从不加载详细视图

请给我一些点击,有什么问题吗?

#pragma mark - Table view delegate

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

[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSLog(@"selected rows");

MyBookDetailView *c = [[MyBookDetailView alloc] init];

[self.navigationController popToRootViewControllerAnimated:NO];
[self.navigationController pushViewController:c animated:YES];
}

我也尝试 performSelectorOnMainThread 但它仍然只是可点击的并且我在加载我的视图控制器时遇到问题,我还在 - (void)viewDidLoad 方法中添加了委托,

提前致谢!

最新代码:

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


[tableView deselectRowAtIndexPath:indexPath animated:YES];
MyBookDetailView *c = [[MyBookDetailView alloc] initWithNibName:@"MyBookDetailView" bundle:nil];

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

}

【问题讨论】:

  • 你能检查两件事吗: 1. MyBookDetailView 上的 viewDidLoad 方法是否被调用? 2.去掉这条语句后能不能试试:[self.navigationController popToRootViewControllerAnimated:NO];
  • Pop 和 Push in 一起。如果 navigationController 不为零。我建议一次性操作 viewControllers 堆栈的 navigationController 来处理它。
  • @AC1 我把 NsLog 放在 viewDidLoad MyBookDetailView 上,但它从不打印它,我也删除了这个语句 [self.navigationController popToRootViewControllerAnimated:NO];但什么也没发生
  • 那么你的 self.navigationController 很可能是 nil 。你能证实吗?你的自我嵌入在导航控制器中了吗?

标签: iphone objective-c ios5 uiviewcontroller uitableview


【解决方案1】:

为什么要将所有带有导航控制器堆栈的控制器弹出到根控制器,同时又要推送新的 MyBookDetailView(我希望它的基类是 UIViewController)。

无论如何,MyBookDetailView *c = [[MyBookDetailView alloc] init]; 也不适合你。因为 UIViewController (MyBookDetailView) 视图的 c 对象为 nil。我建议使用断点跟踪执行堆栈和您尝试删除并在运行时添加的变量,您将更好地了解程序中发生了什么。

我认为以下代码可能对您有用,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    MyBookDetailView *c = [[MyBookDetailView alloc] initWithNibName:@"WriteYourNibNameIfYouCreate" bundle:nil];

    [self.navigationController pushViewController:c animated:YES];
}

【讨论】:

  • 感谢您的回复,MyBookTableView 是 UITableViewController 并且 MyBookDetailView 是 UIViewController 您的代码不起作用
  • 这里是 myBookTableView pastebin.com/6EcTcPBM,这里是 detailView pastebin.com/XjxJxQsV
  • @ElnazShahmehr 我正在谈论/关于 MyBookDetailView 类 nib 及其基础类。如果 MyBookDetailView 类有 nib 文件,那么您必须在分配时间提及其名称。
  • 是的,我会发给你最新的
  • 我还是找到了 MyBookDetailView *c = [[MyBookDetailView alloc] init]; ....initWithNibName:bundle 方法在哪里。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多