30 個のフィールド (ラベル、テキストフィールド、星の評価、およびその他の UIView、picercontrol) を含むテーブルビューがあります。問題は、テーブルビューをスクロールするとセルが置き換えられることです。これに対する解決策はありますか? 編集:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ReuseCell";
// UIColor* mainColor = [UIColor colorWithRed:43.0/255 green:128.0/255 blue:191.0/255 alpha:1.0f];
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ;
if (indexPath.section==0) {
if (indexPath.row==0) {
productImage=[self createImageWithFrame: CGRectMake(115.5, 10, 89,89)];
productImage.tag=indexPath.row+indexPath.section;
[cell.contentView addSubview: productImage];
}
else{
titleLabel1=[self createLabelWithFrame:CGRectMake(4, 5, 100, 30)];////normal label
titleLabel1.tag=indexPath.row+indexPath.section;
[cell.contentView addSubview:titleLabel1];
titleLabel1.text=[labelArray objectAtIndex:indexPath.row-1];
if (indexPath.row==2) {
productImage=[self createImageWithFrame: CGRectMake(104, 10, 190,20)];
productImage.tag=indexPath.row+indexPath.section;;
[cell.contentView addSubview: productImage];
}
else if (indexPath.row==7) {
titleLabel1=[self createLabelWithFrame:CGRectMake(4, 5, 100, 30)];////time label
titleLabel1.tag=indexPath.row+indexPath.section;
[cell.contentView addSubview:titleLabel1];
}
else if (indexPath.row==8) {
titleLabel1=[self createLabelWithFrame:CGRectMake(4, 5, 100, 30)];///time label
titleLabel1.tag=indexPath.row+indexPath.section;
[cell.contentView addSubview:titleLabel1];
}
else if (indexPath.row==9) {
descriptionText=[[UITextView alloc]initWithFrame:CGRectMake(104, 10, 190, 50)];
descriptionText.tag =indexPath.row+indexPath.section;
[cell.contentView addSubview:descriptionText];
}
else{
textFld=[self createTextFieldWithFrame:CGRectMake(104, 10, 190, 20)];
textFld.tag=indexPath.row+indexPath.section;
[cell.contentView addSubview:textFld];
textFld.text=[labelArray objectAtIndex:indexPath.row-1];
}
}
}
}
///////trying to resuse the cell
if (indexPath.section==0) {
if (indexPath.row==0) {
productImage=(UIImageView *)[cell.contentView viewWithTag:indexPath.row+indexPath.section];
//productImage.image=
}
else{
titleLabel1=(UILabel *)[cell.contentView viewWithTag:indexPath.row+indexPath.section];
titleLabel1.text=[labelArray objectAtIndex:indexPath.row+indexPath.section-1];
if (indexPath.row==2) {
// productImage=[self createImageWithFrame: CGRectMake(104, 10, 190,20)];
}
if (indexPath.row==7) {
// titleLabel1=(UILabel *)[cell.contentView viewWithTag:indexPath.row+indexPath.section];////time label
}
if (indexPath.row==8) {
// titleLabel1=(UILabel *)[cell.contentView viewWithTag:indexPath.row+indexPath.section];;///time label
}
// textFld=(UITextField *)[cell.contentView viewWithTag:indexPath.row+indexPath.section];
if (indexPath.row==9) {
}
}
}
編集:1 セクションの 7 セクションを残す:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ReuseCell";
// UIColor* mainColor = [UIColor colorWithRed:43.0/255 green:128.0/255 blue:191.0/255 alpha:1.0f];
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ;
cell.tag=indexPath.row;
if (indexPath.row!=0) {
titleLabel1=[self createLabelWithFrame:CGRectMake(4, 5, 100, 30)];
titleLabel1.tag=indexPath.row+indexPath.section;
[cell.contentView addSubview:titleLabel1];
}
NSLog(@"%d",indexPath.row);
}
else{
titleLabel1=(UILabel *)[cell.contentView viewWithTag:indexPath.row+indexPath.section];
}
if (indexPath.row!=0)
titleLabel1.text=[labelArray objectAtIndex:indexPath.row+indexPath.section-1];
return cell;
}
and my labelArray is:
labelArray=[[NSMutableArray alloc]initWithObjects:@"*Name",@"Category",@"Brand",@"Model",@"Serial no",@"Bill no",@"*Purchase date",@"*Expiry Date",@"Description",nil];