2013-03-13 82 views
0

我正在建立一些類的信息指南。我需要使用UITableView,少了這個東西看起來像垃圾,所以我一直在爲它工作了大約一個星期。與UITableView的NSInvalidArgumentException?

我收到的錯誤是在NSInvalidArgumentException下面的代碼:

- (NSInteger)numberOfRowsInSection:(NSInteger)section{ 
/*NSDictionary *dict = [_allPerks objectAtIndex:section]; 
NSArray *temp = [dict objectForKey:@"Perks"]; 
return [temp count];*/ 
if (section == 0) 
    return 9; 
else if (section ==1) 
    return 7; 
else if (section ==2) 
    return 11; 
else if (section == 3) 
    return 11; 
else if (section == 4) 
    return 8; 
else 
    return 0; 

} 

至少,我認爲它的存在。該錯誤指出我的問題在於該功能,關於它具有無效的發件人。被評論的代碼是我第二次嘗試不起作用。

這也是一個分組表,以防萬一。我使用一個數組數組來實現這個,因爲我需要組織很多元素。如果代碼是必要的,就這麼說吧。

回答

0

試試這個代碼

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 

    if (section == 0){ 
      return 9; 
    } 
    else if (section ==1){ 
      return 7; 
    } 
    else if (section ==2){ 
      return 11; 
    } 
    else if (section == 3){ 
      return 11; 
    } 
    else if (section == 4){ 
      return 8; 
    } 
    else{ 
      return 0; 
    } 
} 
0

確保你的方法簽名匹配這樣的:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 

,而不是這樣的:

- (NSInteger)numberOfRowsInSection:(NSInteger)section