データが表示されるUITableView
場所がありますが、スクロールするとデータ(UILabel
)が消えるか、データが何度も重ねて追加されます。すべてのセルをスクロールすると、データが交換されます。
これが私のcellForRowAtIndexPath:
コードです
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// configure the cell's background
UIImageView *gradient = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gradient"]];
[cell.contentView addSubview:gradient];
// configure the cell's label
UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(50, 130, 300, 44)];
// grab a reference to the label's text from the tableData
nameLabel.text = [name objectAtIndex:indexPath.row];
nameLabel.textColor = [UIColor blackColor];
nameLabel.font = [UIFont fontWithName:@"DIN-Bold" size:12];
nameLabel.backgroundColor = [UIColor clearColor];
// set the autoReiszing mask -- this way if the label spills over the editing
// [icon?] then the text will trail off in ...
nameLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[cell.contentView addSubview:nameLabel];
// configure the cell's label
UILabel *tableTextViewLbl = [[UILabel alloc] initWithFrame:CGRectMake(50, 80, 220, 50)];
// grab a reference to the label's text from the tableData
tableTextViewLbl.text = [message objectAtIndex:indexPath.row];
tableTextViewLbl.textColor = [UIColor blackColor];
tableTextViewLbl.font = [UIFont fontWithName:@"DIN" size:10];
tableTextViewLbl.backgroundColor = [UIColor clearColor];
tableTextViewLbl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[cell.contentView addSubview:tableTextViewLbl];
// configure the cell's label
UILabel *tableTimeStampViewLbl = [[UILabel alloc] initWithFrame:CGRectMake(50, 30, 200, 50)];
// grab a reference to the label's text from the tableData
tableTimeStampViewLbl.text = [timeStamp objectAtIndex:indexPath.row];
tableTimeStampViewLbl.textColor = [UIColor lightGrayColor];
tableTimeStampViewLbl.font = [UIFont fontWithName:@"DIN" size:7];
tableTimeStampViewLbl.backgroundColor = [UIColor clearColor];
tableTimeStampViewLbl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[cell.contentView addSubview:tableTimeStampViewLbl];
// UIImageView *image;
// UIImage *image1=[UIImage imageNamed:@"rest.png"];
// image=[[UIImageView alloc]initWithImage:image1];
// image.frame=CGRectMake(10,30,40,30);
//
// [cell.contentView addSubview:image];
//
return cell;
}