我的表格视图中有一个非常奇怪的问题。
我为表格视图使用不同的部分,每个部分都有不同的行数。我在表格视图的单元格中有一些文本字段。问题是,当我向下滚动表格视图时,第一节文本字段的第一个单元格和最后一节第一行文本字段相互重叠。当我向上滚动表格视图时,也会发生同样的事情。
static NSString *cellIdetifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdetifier];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdetifier];
}
cell.detailTextLabel.textColor = [UIColor blackColor];
if(indexPath.section == 0)
{
if(indexPath.row == 0)
{
titleAdded = 1;
self.nameView.backgroundColor = [UIColor clearColor];
self.eventName.textColor = [UIColor colorWithRed:128.0/255.0 green:128.0/255.0 blue:128.0/255.0 alpha:1.0];
[cell addSubview:self.nameView];
}
else if (indexPath.row == 1)
{
NSLog(@"in section 0");
self.locationView.backgroundColor = [UIColor clearColor];
self.locationField.textColor = [UIColor colorWithRed:128.0/255.0 green:128.0/255.0 blue:128.0/255.0 alpha:1.0];
[cell addSubview:self.locationView];
}
}
else if (indexPath.section == 1)
{
if(indexPath.row == 0)
{
cell.textLabel.text = NSLocalizedString(@"Starts", @"");
if(self.selectedDate != nil)
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
//[formatter setDateFormat:@"yyyy-mm-dd"];
[formatter setDateStyle:NSDateFormatterFullStyle];
NSString *stringFromDate = [formatter stringFromDate:self.selectedDate];
cell.detailTextLabel.text = stringFromDate;
}
}
else if(indexPath.row == 1)
{
cell.textLabel.text = NSLocalizedString(@"Ends", @"");
if(self.selectedDate != nil)
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
//[formatter setDateFormat:@"yyyy-mm-dd"];
[formatter setTimeStyle:NSDateFormatterShortStyle];
NSString *stringFromDate = [formatter stringFromDate:self.selectedTime];
cell.detailTextLabel.text = stringFromDate;
}
}
}
else if (indexPath.section == 2)
{
if(indexPath.row == 0)
{
cell.textLabel.text = NSLocalizedString(@"Repeat",@"");
cell.detailTextLabel.text = NSLocalizedString(@"Never", @"");
}
}
else if (indexPath.section == 3)
{
if(indexPath.row == 0)
{
cell.textLabel.text = NSLocalizedString(@"Alert", @"");
if(![[[NSUserDefaults standardUserDefaults] valueForKey:@"ringtone"] isEqualToString:@""] && [[NSUserDefaults standardUserDefaults] valueForKey:@"ringtone"] != nil)
{
cell.detailTextLabel.text = [[NSUserDefaults standardUserDefaults] valueForKey:@"ringtone"];
}
else
{
cell.detailTextLabel.text = NSLocalizedString(@"None", @"");
}
}
}
else if (indexPath.section == 4)
{
if(indexPath.row == 0)
{
cell.textLabel.text = NSLocalizedString(@"Calendar", @"");
cell.detailTextLabel.text = NSLocalizedString(@"Home", @"");
}
}
else if(indexPath.section == 5 && indexPath.section != 0)
{
if(indexPath.row == 0)
{
self.urlView.backgroundColor = [UIColor clearColor];
self.urlField.textColor = [UIColor colorWithRed:128.0/255.0 green:128.0/255.0 blue:128.0/255.0 alpha:1.0];
[cell addSubview:self.urlView];
}
}
这是我的cellforRowatIndexPath
任何解决方法的代码。我已经对其进行了调试,当它出现在第 5 节 if 语句时,它找不到节值,它直接跳到 if 语句中。然后问题就出现了。我还检查了它是否为零但没有用。