它是如此奇怪:爲什麼NSArray的objectAtIndex:對的tableView titleForHeaderInSection錯誤部分:指數0超越界限的空數組
_tableDataSectionTitles是這樣的UITableViewController子類&一個NSArray的屬性。
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
NSLog(@"%@", _tableDataSectionTitles); // returns: ("string")
NSLog(@"%@", [_tableDataSectionTitles objectAtIndex:0]); // returns: "string"
NSLog(@"%i", section); // returns 0
NSLog(@"%@", [_tableDataSectionTitles objectAtIndex:section]; // returns "string"
return [_tableDataSectionTitles objectAtIndex:section]; // returns: *** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array
那是什麼!? (其他所有的東西都正常工作,我檢查了三次)(認真的說,這就像是第一件事情,所以沒有什麼應該是錯的)
我也試過了, array:
NSString *rep = [[NSString alloc] init];
if (section == 0) {
rep = @"Stuff";
} else { // doesn't even need it - it won't run through it anyway
//rep = [_tableDataSectionTitles objectAtIndex:section]; // commented out just to not have any doubts
}
return rep;
但仍然是相同的錯誤。幫幫我!
if(section == 0){return [_tableDataSectionTitles objectAtIndex:section]; } else {return「你想要的任何東西」} –
粘貼從調試控制檯出現的那些NSLogs的實際輸出。不要試圖將其重新輸入爲評論。 –