iOS6에서 UITableViewCell 위에 올라간 UILabel, UIButton 등의 객체를 참조할 때의 코드가 iOS7에서 조금 변경되었다.

- iOS6

    UITableViewCell

      ↳  UITableViewCellContentView

           ↳ UILabel ...


- iOS7

    UITableViewCell

      ↳ UITableViewCellScrollView  <- 추가됨.

           ↳ UILabel...

           ↳ UITableViewCellContentView

                ↳ UILabel ...


그래서 iOS6에서 Cell 아래에 있는 Label등에 접근할 때, 또는 Cell 위에 아래와 같이 버튼을 올렸을 경우

  UIButton *button3 = [UIButton buttonWithType:UIButtonTypeCustom];      

  [button3 setFrame:CGRectMake(145100113)];         

  [button3 addTarget:self action:@selector(cellButtonAction:) 

     forControlEvents:UIControlEventTouchUpInside];

  [cell.contentView addSubview:button3];


- iOS6까지는 아래와 같이 접근이 가능했음.

        UITableViewCell *cell = (UITableViewCell *)[[(UIView *) sender superviewsuperview];

    UITableView *tableView = (UITableView *)[cell superview];

    NSIndexPath *cellIndexPath = [tableView indexPathForCell:cell];

    NSUInteger row = [cellIndexPath row];


- iOS7 에서는 Cell과 ContentView 사이에 UITableViewCellScrollView 가 추가되고, 

UITableView와 Cell 사이에 UITableViewWrapperView가 추가되었다. 그래서 접근하기 위해서는 superview가 더 필요하다.

    UITableViewCell *cell = (UITableViewCell *)[[[(UIView *) sender superviewsuperviewsuperview];

    UITableView *tableView = (UITableView *)[[cell superviewsuperview];

    NSIndexPath *cellIndexPath = [tableView indexPathForCell:cell];

    NSUInteger row = [cellIndexPath row];


UITableViewCellScrollView?

  - UITableViewCell에 추가된 Private Class.

  - iOS7에서 Cell을 삭제할 때 왼쪽으로 스크롤해야하는데, 이 때 사용되는 것으로 보임.


UITableViewWrapperView? 

  - Private Class 같은데, 용도를 아직 모르겠음. 

--------------------------

추가사항. 

위에서 예로 든 경우 superview를 이용해서 접근하고 있는데, 아래와 같은 방법으로 이용하는게 좀 더 안전한 방법임을 다른 분이 알려줌.


- (void)btnPressed:(id)sender

{

   CGPoint btnPos = [sender convertPoint:CGPointZero toView:tableView];

   NSIndexPath *ip = [tableView indexPathForRowAtPoint:btnPos];

   if (ip != nil) {

      ...

   }

}


Posted by 프리지크
:

BLOG main image
인생에서는 찾고, 노력하고, 희생할 각오가 되어 있는 것만 얻을 수 있다. (조시 매슈 애덤스) by 프리지크

공지사항

카테고리

분류 전체보기 (121)
끄적끄적 (16)
좋은 글 (9)
자료 (19)
런닝&피트니스 (18)
기술 (43)
기사 스크랩 (1)
내가 본 공연 후기 (1)
내가 가 본 맛집 (5)
괜찮아 보이는 펜션들 (4)
(4)
한장한장 (0)
비공개 스크랩 (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

Total :
Today : Yesterday :