테이블보기 셀의 모든 항목에 대해 오른쪽에 단추가 있어야하고 왼쪽에 단추가 있어야합니다. 버튼 클릭 이벤트에서 텍스트 (왼쪽/오른쪽 버튼 클릭)를 변경하고 텍스트 조건에 따라 버튼 중 하나를 제거해야합니다. cellForRowAtIndexPath 메서드를 사용하여 단추를 제거 할 수 없습니다. UITableViewCell 하위 클래스 시도하고 메서드를 사용하여 -prepareForReuse하지만 셀을 다시 설정할 수 없습니다. 어떤 아이디어를 어떻게 얻을 수 있습니까? 아니면이 버튼을 보이지 않게하거나 숨길 수있는 방법이 있습니까? 당신이 할 수있는 것들UITableViewCell이 업데이트되지 않음
NSString *CellIdentifier = [[NSString alloc] initWithFormat:@"Cell%d",indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
[self.tableView clearsContextBeforeDrawing];
NSString *str = [listOfItems objectAtIndex:indexPath.row];
cell.text = [listOfItems objectAtIndex:indexPath.row];
cell.textColor = [UIColor blueColor];
cell.font = [UIFont systemFontOfSize:14];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIImage *image = [UIImage imageNamed:@"Arrow_Right.png"];
CGRect frame = CGRectMake(290, 5, image.size.width, image.size.height);
button.frame = frame;
[button setBackgroundImage:image forState:UIControlStateNormal];
button.backgroundColor = [UIColor clearColor];
[button addTarget:self action:@selector(rightArrow_clicked:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIImage *img = [UIImage imageNamed:@"Arrow_Left.png"];
CGRect frame1 = CGRectMake(5, 5, img.size.width, img.size.height);
button1.frame = frame1;
[button1 setBackgroundImage:img forState:UIControlStateNormal];
button1.backgroundColor = [UIColor clearColor];
[button1 addTarget:self action:@selector(leftArrow_clicked:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button1];
if([str isEqual:@" abc "])
[button setEnabled:NO];
if([str isEqual:@" pqr "])
[button1 setEnabled:NO];
예 재사용 가능한 셀입니다. -prepareForReuse 메소드에서 어떻게 재설정합니까? – Neo