별도의 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");
}
음 ... 코드를 보지 않고. – rdelmar
문제를 조사 할 수 있도록 관련 코드 부분을 제공해주십시오. – fluidsonic
죄송합니다. 지금 추가했습니다. 내가 layoutSubviews가 매번 호출되고 있기 때문에 그것이 있어야한다는 것을 알지만, 나는 이유를 이해하지 못한다. – crashlog