I benutzerdefinierte Zelle UILabel
, UIImageView
, unter Verwendung von konstantem Tag für UILabel
, UIImageView
mit dynamischem Tag enthält am Erstellen die Tabelle 11 Zellen haben, die ersten richtig geladen 7-Zellen, die 8, 9, 10, 11 Zelle Bildansicht ändern, wenn ich die 1, 2, 3, 4, Zelle jeweils in der Tabelle ändern, auch die Tags sind in den Zellen gleich, ich verwende die Bilder zum Kontrollkästchen in der Tabelle, UITapGestureRecognizer
verwendet, um zu ändern Imageview in der Tabelle,warum Tag in tableview zu reuseing Zellen verändert
ich diesen Code verwenden .....
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier [email protected]"Cell";
UITableViewCell *cell = [tableview dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ;
cell.selectionStyle=UITableViewCellSelectionStyleGray;
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
UIImageView *imageview=[[UIImageView alloc]initWithFrame:CGRectMake(5, 12, 20, 20)];
imageview.tag=n;
[cell.contentView addSubview:imageview];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tabimage:)];
imageview.userInteractionEnabled=YES;
[imageview addGestureRecognizer:tap];
imageview.image=[UIImage imageNamed:@"img1.jpeg"];
UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, 2, 260,26)];
titleLabel.tag=222;
titleLabel.backgroundColor=[UIColor clearColor];
[cell.contentView addSubview:titleLabel];
UILabel *dateLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, 31, 260, 13)];
dateLabel.tag=333;
dateLabel.font=[UIFont systemFontOfSize:10];
dateLabel.backgroundColor=[UIColor clearColor];
[cell.contentView addSubview:dateLabel];
}
UIImageView *imageview1=(UIImageView*)[cell.contentView viewWithTag:n];
if([array containsObject:[NSNumber numberWithInt:imageview1.tag]]) {
imageview1.image=[UIImage imageNamed:@"img2.jpeg"];
} else {
imageview1.image=[UIImage imageNamed:@"img1.jpeg"];
}
UILabel *titlelable=(UILabel*)[cell.contentView viewWithTag:222];
titlelable.text=[task objectAtIndex:indexPath.section];
NSLog(@"%i",indexPath.section);
UILabel *dateLabel=(UILabel*)[cell.contentView viewWithTag:333];
dateLabel.text=[date objectAtIndex:indexPath.section];
n++;
return cell;
}
- (void)tabimage:(id)sender {
UIImageView *iv=(UIImageView *)[sender view];
int i=iv.tag;
NSLog(@"------------%i",i);
if (iv.image==[UIImage imageNamed:@"img1.jpeg"]) {
iv.image= [UIImage imageNamed:@"img2.jpeg"];
[array addObject:[NSNumber numberWithInt:i]];
} else {
iv.image= [UIImage imageNamed:@"img1.jpeg"];
[array removeObject:[NSNumber numberWithInt:i]];
}
}
.. . und? Was ist dein Problem? – Cyrille