我有一個字符串數組,並希望我的UITableView中的每個部分使用各自的字符串作爲其行的標題。而不是這樣做,它只是取出數組中的第一個字符串,然後在每個部分重複它。UITableView重複每個部分的單元格中的相同字符串
我似乎無法弄清楚我在做什麼錯了設置。我有indexPath.section
和agendaTableArray
值記錄,並且在滾動表格時它會正確記錄,但它仍然只顯示第一個值。
陣列設置:
- (void)viewDidLoad
{
[super viewDidLoad];
/// code clipped for brevity
self.agendaTableArray = [[NSArray alloc] init];
self.agendaTableArray = @[@"No events today!", @"No events today!", @"Dinner with Rebekah", @"Soccer game", @"Dentist appt.", @"Celebrate job offer, drinks with Pierre!", @"No events today!", @"No events today!", @"No events today!", @"No events today!", @"No events today!", @"No events today!", @"No events today!", @"No events today!", @"No events today!", @"No events today!", @"No events today!"];
}
表設置:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyReuseIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier];
}
NSLog(@"the indexpath.section is: %ld", (long)indexPath.section);
NSLog(@"the agendaTableArray title is: %@", self.agendaTableArray[indexPath.section]);
cell.textLabel.text = self.agendaTableArray[indexPath.row];
cell.textLabel.font = [UIFont systemFontOfSize:14];
[self whatSectionsAreVisible];
return cell;
}
請加上你的numberofRows和numberOfSection方法,好像你顛倒了數據源實現 – Doro
這是不是你的[上一個問題]的重複(http://stackoverflow.com/questions/31059765/how-to-have - 每個字符串功能於一個陣列待其-自有的UITableViewCell-每個-在其通自己的)? – rmaddy