테이블의 선택된 행에 버튼이 있어야합니다. 1 시간 동안로드 될 때iPhone 용 UITableView 특정 행의 캔트 표시 버튼
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *ControlRowIdentifier = @"ControlRowIdentifier";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:ControlRowIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:ControlRowIdentifier] autorelease];
}
if ([indexPath row] > 5) {
UIImage *buttonUpImage = [UIImage imageNamed:@"button_up.png"];
UIImage *buttonDownImage = [UIImage imageNamed:@"button_down.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0, 0.0, buttonUpImage.size.width, buttonUpImage.size.height);
[button setBackgroundImage:buttonUpImage forState:UIControlStateNormal];
[button setBackgroundImage:buttonDownImage forState:UIControlStateHighlighted];
[button setTitle:@"Tap" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = button;
}
NSUInteger row = [indexPath row];
NSString *rowTitle = [list objectAtIndex:row];
cell.textLabel.text = rowTitle;
return cell;
}
이 코드는 절대적으로 잘 작동 : 여기
내가 사용하고있는 예제 코드입니다. 따라서 논리에 따라 5보다 큰 모든 행에 대해 '탭'버튼이 표시됩니다.위아래로 스크롤 할 때 문제가 발생합니다. 일단 그렇게하면 버튼을 임의의 행에두기 시작합니다. 나는 그것이 왜 그렇게하는지 이해하지 못한다. 누군가가 이것에 관해 조언을 해줄 수 있다면 정말 도움이 될 것이다.
감사합니다.
감사합니다 Victor! 문제는 실제로 셀 식별자의 재사용과 관련되어있었습니다. 고유 식별자를 사용하면 문제가 사라졌습니다. – user315603
유일한 식별자는 독특한 특성을 가진 셀을 필요로합니다.이 경우 버튼이있는 셀과 버튼이없는 셀이 있습니다. 각 셀마다 고유 한 식별자를 생성하면 재사용이 중단되어 효율성에 영향을 미칩니다. – Victor