2012-02-15 4 views
0

콘텐츠 목록을 표시하는 UITableView가 있으며 목록의 각 항목에 사용자가 터치하여 표시하거나 해제 할 수있는 확인란이 있어야합니다. 각 셀에 대해 UIButton을 만들고 셀의 accessoryView로 설정 한 다음 호출 할 대상 메서드를 추가했습니다.프로그래밍 방식으로 추가 된 UIButton 터치 이벤트에 대해 "인식 할 수없는 선택기를 인스턴스로 보냄"오류 발생

그러나 확인란을 클릭 할 때마다 항상 "인스턴스로 전송 된 인식 할 수없는 선택기"오류가 발생하며 이유가 없습니다. 그 장소를 둘러보고 오류의 원인을 찾아 내 addTarget 호출과 선택한 메서드가 올바른 구문을 사용하는지 확인했지만 어쩌면 내가 누락되었습니다. 이 오류를 수정하려면 무엇을 변경해야합니까?

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 

     // Set up the cell... 
     PFObject *tempMap = [searchResults objectAtIndex: [indexPath row]]; 
     cell.textLabel.text = [tempMap objectForKey:@"mapName"]; 

     // Add checkbox to cell 
     UIButton *checkBox = [UIButton buttonWithType:UIButtonTypeCustom]; 
     checkBox.bounds = CGRectMake(0, 0, 30, 30); 
     cell.accessoryView = checkBox; 
     checkBox.tag = indexPath.row; 
     [checkBox setImage:[UIImage imageNamed:@"checkbox.png"] forState:UIControlStateNormal]; 
     [checkBox setImage:[UIImage imageNamed:@"checkbox-checked.png"] forState:UIControlStateSelected]; 
     [checkBox setImage:[UIImage imageNamed:@"checkbox-pressed.png"] forState:UIControlStateHighlighted]; 

     [checkBox addTarget:self action:@selector(checkBoxButton:) forControlEvents:UIControlEventTouchUpInside]; 
     [cell addSubview:checkBox]; 
    } 
    return cell; 
} 

이, checkBoxButton라고되고있는 방법이다 : 여기

은 세포 생성을위한 코드를 당신이 선택 checkBoxButton:를 등록하고

- (void)checkboxButton:(id)sender 
{ 
    UIButton *checkBox = sender; 

    if (checkBox.selected) 
    { 
     [selectedMaps removeObject:[searchResults objectAtIndex:checkBox.tag]]; 
     NSLog(@"..Map Deselected.."); 
    } 
    else 
    { 
     [selectedMaps addObject:[searchResults objectAtIndex:checkBox.tag]]; 
     NSLog(@"..Map Selected.."); 
    } 
} 

답변

2

을하지만 실제로 구현하고 checkboxButton: (첫 번째 "B"의 대소 문자 차이점에 유의하십시오).

+0

아하하 나는 바보 야! 이 명백한 오류를 지적 해 주셔서 감사합니다. 아마 그 질문을 삭제할 것입니다. – desmondhume

+0

@desmondhume, FYI, 답변을 얻은 후에는 질문을 삭제할 수 없습니다. 또 하나, 이것은 전혀 추천 할 수 없습니다 (이로 인해 귀하의 계정이 영구적으로 잠길 수 있습니다). 따라서 올바른 대답을 더 잘 받아들이는 것이 유일한 좋은 방법입니다. StackOverflow는 질문 유형 (바보/아인슈타인)을 결코 비교하지 않습니다 :) – Hemang

관련 문제