У меня есть UITableView
, в котором каждый UITableViewCell
имеет UIView
на них и выше UIView
, у меня есть два UIButton
и два UILabel
.Моя проблема заключается в том, что когда я перезагружаю табличное представление, то новые данные перезаписываются на старые данные, что делает содержимое размытым и нечетким, и в методе cellForRowAtIndexPath
я использовал этот код удаления метки, тогда он также не работает должным образом .......
NSArray *subviews = [[NSArray alloc] initWithArray:cell.contentView.subviews];
for (UILabel *subview in subviews) {
[subview removeFromSuperview];
}
[subviews release];
Этот код показывает строку за раз, иначе никто ...
Код cellForRowAtIndexPath
такой ...
- (UITableViewCell *)tableView:(UITableView *)tableView1 cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"Cell";
UITableViewCell *cell = [tableView1 dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
NSDictionary *dict = [appDelegate.webDataList objectAtIndex:indexPath.row];
tableView.backgroundColor = [UIColor colorWithRed:0.39 green:0.39 blue:0.39 alpha:0.39];
if([appDelegate.dataArray count]>0){
imgView.backgroundColor = [UIColor clearColor];
imgView =[[UIView alloc ] initWithFrame:CGRectMake(0,0,320,45)];
imgView.tag= indexPath.row+250;
[cell.contentView addSubview:imgView];
button=[UIButton buttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(291, 5, 19, 21);
img =[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"swap_re" ofType:@"png"]];
[button setBackgroundImage:img forState:UIControlStateNormal];
[button addTarget:self action:@selector(swapButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
button.tag= indexPath.row+250;
[imgView addSubview:button];
button=[UIButton buttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(-25, 5, 19, 21);
img =[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"swap_re" ofType:@"png"]];
[button setBackgroundImage:img forState:UIControlStateNormal];
[button addTarget:self action:@selector(swapButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
button.tag= indexPath.row+250;
[imgView addSubview:button];
button=[UIButton buttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(5, 7, 19, 21);
button.tag = indexPath.row+250;
img =[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"delete" ofType:@"png"]];
[button setBackgroundImage:img forState:UIControlStateNormal];
[button addTarget:self action:@selector(deleteButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[imgView addSubview:button];
NSArray *arr = [[appDelegate.dataArray objectAtIndex:indexPath.row] componentsSeparatedByString:@"/"];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(34,9,140,20)];
label.text = [arr objectAtIndex:1];
label.tag = indexPath.row+250;
[label setFont:[UIFont fontWithName:@"Georgia" size:14]];
[label setNumberOfLines:0];
label.textAlignment = UITextAlignmentLeft;
label.textColor = [UIColor whiteColor];
label.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
label.backgroundColor = [UIColor clearColor];
[imgView addSubview:label];
[label release];
NSDictionary *dict1 =[appDelegate.webDataList objectAtIndex:indexPath.row];
label = [[UILabel alloc] initWithFrame:CGRectMake(181, 7, 75, 20)];
label.tag = indexPath.row+250;
label.text = [dict1 objectForKey:@"time"];
[label setFont:[UIFont fontWithName:@"Georgia" size:16.0]];
label.textAlignment = UITextAlignmentLeft;
[label setBackgroundColor:[UIColor clearColor]];
label.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
[label setTextColor:[UIColor whiteColor]];
[imgView addSubview:label];
[label release];
}
return cell;
}
и в моем коде я не могу использовать метод reuseTableViewCellWithIdentifier:
, потому что я хочу, чтобы каждый ярлык и метка кнопки были одинаковыми, потому что я должен получить их где-то еще.