2014-10-01 3 views
0

별도의 UITableViewCell을 호출하는 tableview가 있습니다. UITableViewCell에 셀을 배치하는 코드가 있는데이 코드는 내 tableview에 올바르게 표시됩니다. 어떤 이유로 셀을 선택하면 셀의 내용이 셀 위쪽에 다시 그려집니다.셀을 선택하면 TableViewCell 내용이 복제됩니다.

왜 이런 사람이 될지 알고 있습니까? 아래에 셀을 그리는 코드를 첨부했습니다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

if (tableView == productInformationTable){ 

    if (indexPath.row == 0) { 
     static NSString *CellIdentifier = @"Cell"; 
     ProductImagesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[ProductImagesTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
     } 
     else{ 
      cell = [[ProductImagesTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
     } 
     return cell; 
    } 

    else if (indexPath.row == 1) { 
     static NSString *CellIdentifier = @"Cell"; 
     ProductQuantityTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 

     if (cell == nil) { 
      cell = [[ProductQuantityTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
     } 
     else{ 
      cell = [[ProductQuantityTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
     } 
     return cell; 
    } 

    else if (indexPath.row == 2) { 
     static NSString *CellIdentifier = @"Cell"; 
     ProductButtonsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[ProductButtonsTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
     } 
     else{ 
      cell = [[ProductButtonsTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
     } 
     return cell; 
    } 



    else { 
     static NSString *CellIdentifier = @"Cell"; 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
     } 
     else{ 
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
     } 
     return cell; 
    } 
} 

else { 
    return nil; 
} 

}

내 세포에 대한 코드는 다음과 같습니다 - 그것이 여러 번 전화를받을 수

- (void)awakeFromNib { 

    } 




- (void)setSelected:(BOOL)selected animated:(BOOL)animated { 
    [super setSelected:selected animated:animated]; 

    } 

- (void)layoutSubviews 
{ 
    [super layoutSubviews]; 

    self.contentView.backgroundColor = [UIColor redColor]; 
    customButton = [[SAExpandableButton alloc]initWithFrame:CGRectMake(self.frame.size.width - 50, self.frame.size.height/2 - 15, 30, 30)]; 
    customButton.layer.borderColor = [Styles priceRed].CGColor; 
    customButton.layer.borderWidth = 1.5; 
    customButton.layer.cornerRadius = 15; 
    customButton.expandDirection = SAExpandDirectionLeft; 
    customButton.numberOfButtons = 8; 
    customButton.selectedIndex = 0; 

    quantityLabel = [UILabel new]; 
    quantityLabel.frame = CGRectMake(10, self.frame.size.height/2 - 10, 100, 20); 
    quantityLabel.text = @"Quantity"; 
    [self addSubview:quantityLabel]; 


    customButton.buttonTitles = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8", nil]; 

    [self addSubview:customButton]; 



} 



- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath]; 
if(cell.selectionStyle == UITableViewCellSelectionStyleNone){ 
    return nil; 
} 
return indexPath; 
NSLog(@"willSelectRow called"); 

} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSLog(@"Table Pressed"); 

} 
+0

음 ... 코드를 보지 않고. – rdelmar

+0

문제를 조사 할 수 있도록 관련 코드 부분을 제공해주십시오. – fluidsonic

+0

죄송합니다. 지금 추가했습니다. 내가 layoutSubviews가 매번 호출되고 있기 때문에 그것이 있어야한다는 것을 알지만, 나는 이유를 이해하지 못한다. – crashlog

답변

1

당신은 layoutSubviews에서 셀의 하위 뷰를 만들 수 없습니다. 초기화에는 initWithStyle:reuseIdentifier:을 사용하고 layoutSubviews (따라서 이름)에 배치하십시오.

다른 모든 세포 유형에도 다른 CellIdentifier을 사용해야합니다!

편집 :

당신이 tableView:willSelectRowAtIndexPath:를 사용해야 셀의 선택을 방지하고 선택을 방지하기 위해 nil을 반환합니다.

관련 문제