2013-02-15 2 views
0

iOS 응용 프로그램을 개발 중이며 사용자 정의 UITableViewCell으로 사용자 정의 UITableView 편집 모드를 구현하려고합니다.UITableView 편집 모드에서 UITableView : didSelectRowAtIndexPath : 응답하지 않습니다.

나는 편집 버튼이 있고이 그것을 위해 IBAction를이다 : 나는 UIViewControllerUITableView* _favListdelegate를 연결 한

- (IBAction)editFavList:(id)sender 
{ 
    if ([_favList isEditing]) 
    { 
     [_favList setEditing:NO animated:YES]; 
     [_editButton setTitle:@"Edit" forState:UIControlStateNormal]; 
    } 
    else 
    { 
     [_favList setEditing:YES animated:YES]; 
     [_editButton setTitle:@"Done" forState:UIControlStateNormal]; 
    } 
} 

내가 편집 버튼을 통해 탭 때까지이 UITableViewDelegate 방법은 잘 작동 :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (tableView.editing) 
    { 
     NSNumber* obj = [favsSelected objectAtIndex:indexPath.row]; 
     BOOL selected; 

     if (obj == nil) 
      selected = NO; 
     else 
      selected = [obj boolValue]; 

     FavouriteCell* cell = 
      (FavouriteCell*)[tableView cellForRowAtIndexPath:indexPath]; 

     cell.checked = !selected; 

     // Actualizo el estado en el vector de los favoritos seleccionados 
     [favsSelected insertObject:[NSNumber numberWithBool:!selected] atIndex:indexPath.row]; 
    } 
} 

편집 단추를 누른 후이 메서드는 실행되지 않습니다 (메서드에 중단 점을 추가했기 때문에이 메서드에 대해 확신합니다).

이 사용자 정의 셀 구현 :

#import "FavouriteCell.h" 

const NSInteger EDITING_HORIZONTAL_OFFSET = 35; 

@implementation FavouriteCell 

@synthesize selectIcon = _selectIcon; 
@synthesize favName = _favName; 
@synthesize checked = _checked; 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     self.checked = NO; 
    } 
    return self; 
} 

- (void)setChecked:(BOOL)checked 
{ 
    if (checked == _checked) 
     return; 

    _selectIcon.highlighted = checked; 
    _checked = checked; 
} 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
{ 
    [super setSelected:selected animated:animated]; 

    // Configure the view for the selected state 
} 

+ (NSString *)reuseIdentifier 
{ 
    return @"favouriteCell"; 
} 

- (void)setEditing:(BOOL)editing animated:(BOOL)animated 
{ 
    //self.editing = editing; 

    [super setNeedsLayout]; 
} 

#pragma mark - Private methods 
- (void)layoutSubviews 
{ 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 

    [super layoutSubviews]; 

    if (((UITableView *)self.superview).isEditing) 
    { 
     CGRect contentFrame = self.contentView.frame; 
     contentFrame.origin.x = EDITING_HORIZONTAL_OFFSET; 
     self.contentView.frame = contentFrame; 
     self.accessoryType = UITableViewCellAccessoryNone; 
    } 
    else 
    { 
     CGRect contentFrame = self.contentView.frame; 
     contentFrame.origin.x = 0; 
     self.contentView.frame = contentFrame; 
     self.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 

    [UIView commitAnimations]; 
} 
@end 

하지만 다시 편집 버튼을 통해 탭 (다음, 내가 편집 모드를 종료) 경우, 나는 행, didSelectRowAtIndexPath가 다시 트리거 것를 통해 탭합니다.

왜 내가 잘못 했습니까? 아마도이 문제는 UITableView이 편집 모드에 있는지 여부와 관련이 있습니다. 귀하의 경우에는 YES

에 jQuery과의 allowsSelectionDuringEditing 속성을 :

답변

1

확인 nib 파일 우선은이 Single Selection during editing에있는 tableView editing 속성을 변경해야합니다.

enter image description here

1

당신은 설정해야합니다

_favList.allowSelectionDuringEditing = YES; 
관련 문제