Я прекрасно понимаю, что здесь много проблем, хотя я в тупике и не могу решить это самостоятельно. Я только хочу, чтобы отобразить 4 клетки всего в моем myTableView2
UITableView
, но я нахожу, что мои клетки повторного использования нет сомнений из-за этой линииПроблема повторения с ячейками UITableView
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Я понимаю, если я удалить if(!cell)
линию я мог бы отключить UITableView
от создания новых ячеек, но это не работает, потому что оно требует создания ячейки. Есть предположения? Я разместил свой код ниже.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
{
NSLog(@"CREATING NEW CELL");
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.contentView.autoresizesSubviews = YES;
cell.contentView.clipsToBounds = YES;
}
if (tableView == self.myTableView)
{
if ([[array objectAtIndex:indexPath.row] isKindOfClass:[NSNumber class]])
{
cell.textLabel.text = [[array objectAtIndex:indexPath.row] stringValue];
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
}
else
{
cell.textLabel.text = [array objectAtIndex:indexPath.row];
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
}
}
if (tableView == self.myTableView2)
{
self.myTableView2.opaque = NO;
self.myTableView2.backgroundColor = [UIColor colorWithRed:(0.0/255.0) green:(0.0/255.0) blue:(102.0/255.0) alpha:1.0];
self.myTableView2.backgroundView = nil;
if ([[array2 objectAtIndex:indexPath.row] isKindOfClass:[NSNumber class]])
{
cell.textLabel.text = [[array2 objectAtIndex:indexPath.row] stringValue];
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.numberOfLines = 0;
[cell.textLabel sizeToFit];
cell.textLabel.font = [self fontForCell];
}
else
{
cell.textLabel.text = [array2 objectAtIndex:indexPath.row];
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.numberOfLines = 0;
[cell.textLabel sizeToFit];
cell.textLabel.font = [self fontForCell];
}
}
return cell;
}
другие соответствующие данные:
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (tableView==self.myTableView)
{
return [array count];
}
else if(tableView==self.myTableView2)
{
return [array2 count];
}
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView==self.myTableView)
{
return [array count];
}
else if(tableView==self.myTableView2)
{
return [array2 count];
}
}
Какое поведение вы сейчас видите и что вы ожидаете от этого? – jszumski
Вы связали имя CellIdentifier на раскадровке? –
В настоящее время все мои данные, которые состоят из 3 ячеек, повторяются снова и снова. – Greg