【问题标题】:Error in simulator when try run an app尝试运行应用程序时模拟器出错
【发布时间】:2012-10-17 23:20:54
【问题描述】:

我使用情节提要创建了应用程序。我的应用有一个表格、一些按钮和标签

当我尝试运行我的应用模拟器时会产生错误:Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x719de00'

UIViewController tableView:numberOfRowsInSection: 表示我不能将“numberOfRowsInSection”与“UIViewController”一起使用?

我尝试改用“UITableViewController”,但使用此控制器时,我无法在正确的位置找到适合我的按钮和标签。

我做错了什么?

谢谢。

【问题讨论】:

  • 好吧,试试吧。坚持下去。

标签: objective-c xcode uiviewcontroller ios-simulator uitableview


【解决方案1】:

添加 UITableView 并设置 Datasource 和 Delegate 后,我们必须使用一些 UITableview Delegate 方法。例如 NumberOfRowsInSection、NumberOfSection 等。 请使用基本委托方法或删除 UItableView。

【讨论】:

  • 是的,我知道我应该链接 dataSource 并委托给表视图。我打开 View Controller -> Connections Inspector -> 引用 Outlets:有 dataSource->table viewdelegate->table view
  • 您为 NumberOfSection 添加返回计数,例如 >=1?
  • -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [array count]; }
  • 请检查您的 UIViewController 是否有如下协议声明:
  • 检查 NumberOfSectionsInTableview。您返回多少部分?
【解决方案2】:

您需要将UITableView 委托给UIViewController,打开连接检查器并将“delegate”和“dataSource”条目拖到情节提要上的主视图控制器。

【讨论】:

  • 是的,我知道我应该链接 dataSource 并委托给表视图。我打开了 View Controller -> Connections Inspector -> 引用 Outlets:有 dataSource->table viewdelegate->table view
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-02
  • 2017-07-15
  • 2012-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多