[iOS]custom Cell - Edit 사용 시 밀리지 않는 문제

2013. 6. 20. 16:05제2외국어/iOS

상황 : ViewController 위에 TableView를 올리고, 거기에 Custom Cell 을 사용할 때!!


- 기본 UITableViewCell 을 사용하는 경우, Edit 모드시 자동으로 정렬을 해줍니다. 
  하지만, Custom Cell을 사용하는 경우에 Edit 모드시 아래 이미지같이 자동으로 맞춰 주지 않습니다.


< 문제 >



1. 처음엔 edit 버튼을 눌렀을 때 tableview를 옆으로 이동 시켜주면 되겠구나 하고 TableView를 옮겼더니,
전체가 옯겨졌습니다;;
FAILED


       [UIView animateWithDuration:0.5 animations:^{

                [TableView setFrame:CGRectMake(0, 88, 320, 367)];
        }];
        [TableView setEditing:NO animated:YES];

       

 




2. 검색결과 AutoresizingMask 또는 clipSubview 로 해결하라고해서 해봤는데.. 이 부분은 잘 모르겠습니다.
FAILED


 customCell.m에서 initWithStyle ~ 부분에서

 // AutoresizingMask , contentView에 올리기
titleLabel.autoresizingMask  UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
[self.contentView addSubview:titleLabel];





3. 또 다른 검색결과 awakeFromNib 를 통해 구현
SUCCESS

: custom Cell 의 .m 부분에서 awakeFromNib를 집어 넣습니다. 그리고 아래 소스를 집어넣고 끝.


- (void)awakeFromNib

{
       [super awakeFromNib];
       for(NSLayoutConstraint *cellConstraint in self.constraints){
       [self removeConstraint:cellConstraint];
       id firstItem = cellConstraint.firstItem == self ? self.contentView : cellConstraint.firstItem;
       id seccondItem = cellConstraint.secondItem == self ? self.contentView : cellConstraint.secondItem;

       NSLayoutConstraint* contentViewConstraint =
       [NSLayoutConstraint constraintWithItem:firstItem
                                                           attribute:cellConstraint.firstAttribute
                                                         relatedBy:cellConstraint.relation
                                                               toItem:seccondItem
                                                            attribute:cellConstraint.secondAttribute                                                                              
                                                           multiplier:cellConstraint.multiplier
                                                            constant:cellConstraint.constant];

        [self.contentView addConstraint:contentViewConstraint];

    }

}



< 성공 >





'제2외국어 > iOS' 카테고리의 다른 글

[iOS] Network check and error handling  (0) 2013.08.21
[iOS]통화하기  (0) 2013.05.29
[iOS]Font 관련하여..  (0) 2013.04.26
[iOS] Multitasking : Location  (0) 2013.01.29
[iOS] Multitasking : Audio  (0) 2013.01.24