【问题标题】:NSInvalidArgumentException Error When Using UITabBarController使用 UITabBarController 时出现 NSInvalidArgumentException 错误
【发布时间】:2011-09-09 14:18:48
【问题描述】:

我收到以下错误,但我似乎无法弄清楚发生了什么。请帮帮我。

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UIViewController tableView:numberOfRowsInSection:]:无法识别的选择器发送到实例 0x57405a0”

【问题讨论】:

  • 您在未实现协议的 UIViewController 上调用 UITableViewControllerDelegate 方法 (numberOfRowsInSection:)。这就是我们可以从您提供的内容中告诉您的全部内容。我们需要看看你如何填充你的 UITabBarController。
  • 你想让我展示什么?抱歉,我是 Objective-C 的新手。
  • 你从 numberOfRowsInSection 方法返回什么?
  • - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [array count]; }

标签: iphone xcode uitabbarcontroller


【解决方案1】:

我遇到了类似的问题,但解决方案与 numberOfRowsInSection: 方法无关,因为 Xcode 也指向了该方法。

相反,最重要的问题是我没有设置 UIViewController 的自定义 类 设置...在我的情况下,它是空的,而不是像下面示例图像中的“DetailsVC2”这样的有效类名。一旦我纠正了这个问题,通常的 numberOfRowsInSection: 操作就会被识别并正确调用。

通常,您希望返回数组的计数(例如 tableData),但在我非常简单的情况下,我返回的值是 1。

NSArray *tableData; // Defined somewhere above, and populated prior to the viewDidAppear() operation

 .
 .
 .

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  return 1; // or tableData.count;
}

【讨论】:

    【解决方案2】:

    如果您正在使用:

     - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [array count]; } –
    

    试试:

    NSLog(@"%i", [array count]);
    

    然后看看返回什么。可能数组没有正确分配。

    【讨论】:

      【解决方案3】:

      这可以是任何东西。可能是调用的委托未实现协议,也可能是内存泄漏,在某些已释放内存上进行了调用。很难说这样。尝试使用“分析”进行编译并检查所有警告。

      【讨论】:

      • 我使用“分析”运行时没有任何泄漏。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多