2016-10-14 79 views
0

我的程序崩溃与下面的报告。UITableView崩溃无法识别的选择器发送到实例

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7fb4e1c099b0' 

这里是我对tableview方法的实现。

崩溃日志here

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
     if (section == 0) { 
      return 6; 
     } 
     return 5; 
    } 

任何人都可以知道为什么会发生这种情况吗?

+0

否则,如果如果????和部分只有一个,为什么你需要检查部分是否为0? –

+0

你的'tableview'总是返回1 for'numberOfRowsInSection' –

+0

请分享完整的崩溃日志。 – Adeel

回答

0

错误消息说你要发送的方法tableView:numberOfRowsInSection:添加到UIView对象,该对象不理解该方法。无论你的tableview的数据源是不正确的,或者你打算发送一个不同的方法到UIView。

如果你找不到你的bug的代码行,你可能会共享更多的代码。否则,您发布的代码仅仅是样板文件,无助于您。但那是你的错误信息的含义。

+0

你说得对。在界面生成器中。 tableview数据源和委托已链接到UIView而不是Files所有者。现在问题解决了。 – Prav

0

你只有一个段和语法错误附近否则,如果如果(部分== 0) 它会像对待“如果”内部“否则,如果”

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 2; 
} 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
     if (section == 0) { 
      return 6; 
     } 
     else if (section == 1) { 
      return 3; 
     } 
    } 
0
func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
     return 2 
} 

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    if section == 0 { 
     return firstSectionArray.count 
    }else if section == 1{ 
     return secondSectionArray.count 
    } 
    return 0; 
} 
相关问题