uitableview を何度も上下にスクロールするとスティッキーになり、含まれているすべてのビューもスティッキーになります。
ここに私のコードがあります:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] ;
}
cell.textLabel.text=[NSString stringWithFormat:@" %@",
[SongsNames objectAtIndex:indexPath.row]];
UIImageView *b=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 35, 34)];
b.image=[UIImage imageNamed:@"playbuttone.png"];
[cell.contentView addSubview:b];
[b release];
UIButton *b2=[[UIButton alloc] initWithFrame:CGRectMake(260, 0, 50, 35)];
[b2 setImage:[UIImage imageNamed:@"buye.png"] forState:UIControlStateNormal];
[cell.contentView addSubview:b2];
[b2 release];
cell.textLabel.textColor=[UIColor colorWithWhite:1 alpha:1];
}
更新後:
cell.textLabel.text=[NSString stringWithFormat:@" %@",[SongsNames objectAtIndex:indexPath.row]];
[cell.contentView addSubview:b];
// [b release];
[cell.contentView addSubview:b2];
//[b2 release];
cell.textLabel.textColor=[UIColor colorWithWhite:1 alpha:1];
およびビューでdidload:
- (void)viewDidLoad{
b=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 35, 34)];
b.image=[UIImage imageNamed:@"playbuttone.png"];
b2=[[UIButton alloc] initWithFrame:CGRectMake(260, 0, 50, 35)];
[b2 setImage:[UIImage imageNamed:@"buye.png"] forState:UIControlStateNormal];
}