5 개의 섹션이있는 그룹화 된 tableView가 있습니다. tableView는 2 개의 레이블과 4 개의 버튼이있는 사용자 정의 UITableViewCell을 사용합니다. 테이블의 시작 부분에 하나 이상의 버튼을 선택하고 끝까지 스크롤하면 마지막 셀에서 선택된 버튼을 찾게됩니다. 때로는 마지막 두 번째 버튼에서 찾습니다. dequeueReusableCellWithIdentifier
에는 몇 가지 문제가 있지만 그 사실을 알 수없는 것으로 보입니다. 내 cellForRowAtIndexPath에서빠른 스크롤로 사용자 정의 UITableViewCell 이상한 동작
// table cell
UINib *nib = [UINib nibWithNibName:@"SMRateMeetingTableViewCell" bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:@"SMRateMeetingTableViewCell"];
이 :
SMRateMeetingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SMRateMeetingTableViewCell" forIndexPath:indexPath];
// Configure the cell...
if (cell == nil) {
cell = [[SMRateMeetingTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SMRateMeetingTableViewCell"];
}
아주 기본적인 것들 는 명확하게하기 위해 나는이 내있는 viewDidLoad에서 코드가 있습니다. 더 나은 이해를 위해 몇 가지 화면을 추가했습니다.
EDIT : 단추 코드 추가.
-(IBAction)firstYesButtonAction:(id)sender
{
UIButton *senderButton = (UIButton *)sender;
[self.votesArray replaceObjectAtIndex:(senderButton.tag*2) withObject:[NSNumber numberWithInt:1]];
//NSLog(@"%@", self.votesArray);
}
이것이다 : 버튼에 관련된
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
SMRateMeetingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SMRateMeetingTableViewCell" forIndexPath:indexPath];
// Configure the cell...
if (cell == nil) {
cell = [[SMRateMeetingTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SMRateMeetingTableViewCell"];
}
//the tag will allow me to understand in which section is the button
cell.firstYesButton.tag = indexPath.section;
[cell.firstYesButton addTarget:self action:@selector(firstYesButtonAction:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
그리고 상대 방법 : 쉬운 분석을 위해 이의 내가 만이 테이블보기 코드 사용자 정의 셀 1 개 버튼이 가정하자 사용자 지정 셀의 구현 파일에있는 코드 :
@implementation SMRateMeetingTableViewCell
- (void)awakeFromNib {
// Initialization code
[self.firstYesButton setImage:[UIImage imageNamed:@"yesRateDisable.png"] forState:UIControlStateNormal];
}
- (IBAction)firstYesAction:(id)sender {
[self.firstYesButton setImage:[UIImage imageNamed:@"yesRateEnable.png"] forState:UIControlStateNormal];
}
아래의 제거는 당신은 당신의 버튼 관련 코드를 공유 할 수 있습니다. –
방금 코드로 질문을 편집했습니다. – Diego
문제는 무엇이고 원하는 것은 무엇인지 언급 할 수 있습니까? ? –