2016-10-14 78 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; 
} 
相關問題