2013-09-01 2 views
1

섹션 및 행이있는 tableview가 있습니다. 사용자가 행/섹션 내부의 버튼을 클릭하면 특정 버튼 근처에 UIView이 표시됩니다.행의 단추 근처에 UIView를 추가 하시겠습니까?

- (IBAction) openRoundedPopover:(id)sender { 

btn = (UIButton*) sender; 

//Identify if user clicked header section or cell row 
if (btn.titleLabel.tag == 8) 
    isHeaderViewButtonClicked = YES; // headerview mean when user clicks on section 
else 
    isHeaderViewButtonClicked = NO; 

MainTableViewCell *clickedResourceCell = (MainTableViewCell*)btn.superview.superview; 
CGPoint hitPoint = [sender convertPoint:CGPointZero toView:self.tableView]; 

self.roundedButtonMenu.frame = CGRectMake(43, isHeaderViewButtonClicked ? hitPoint.y+50:clickedResourceCell.frame.origin.y+53, self.roundedButtonMenu.frame.size.width, self.roundedButtonMenu.frame.size.height); 

[self.view addSubview:self.roundedButtonMenu]; 

} 

이 모두 정상적으로 작동합니다. 그러나 사용자가 행/섹션을 계속 추가하고 하단 행/섹션의 버튼을 클릭하면 (즉, 새로 추가 된 행/섹션을 보려면 표 뷰를 아래로 스크롤) 해당 버튼 근처에는 UIView이 표시되지 않습니다. 다른 곳에서 팝업되거나 아예 나타나지 않습니다.

제발 도와주세요! 고맙습니다.

답변

1
MainTableViewCell *clickedResourceCell = (MainTableViewCell*)btn.superview.superview; 

당신이 통제 할 수없는 뷰 계층을 가정하지 마십시오. (이것은 가까운 iOS에서 110 %가 깨질 것입니다.)

그래서 저는 셀 프레임을 얻지 못한다고 가정합니다!

MainTableViewCell *clickedResourceCell = (MainTableViewCell*)btn; 
while(clickedResourceCell.superview && ![clickedResourceCell isKindOfClass:[MainTableViewCell class]]) { 
    clickedResourceCell = (MainTableViewCell*)clickedResourceCell.superview; 
} 

하지만 문제는 당신이있는 ScrollView에하지 않은 elf.view 할 수있는 버튼을 추가한다는 것입니다 .. 그것을 할 수 스크롤 할 때 계산 캔트 정말 일?

그것이 셀에 추가

button.frame = CGRectMake(0,0,100,40); //dummy 
[cell.contentView addSubview:btw]; 
//take care of cell reusing! 
+0

안녕 Daij을, 대답 주셔서 감사합니다! 내가 말한 것처럼 코드를 업데이트했지만 여전히 작동하지 않습니다! 사용자가 tableview를 맨 아래로 스크롤 할 때 UIView가 나타나지 않습니다. 하지만 잘못된 방법으로 셀 값을 검색하는 실수를 바로 잡는 데 도움이됩니다. 감사합니다. – happycoder

+0

조금 편집 ... 셀을 스크롤 할 수있는 경우보기에 단추를 추가하면 작동하지 않습니다. –

+0

셀에 추가하면 (적절하게!) 추가/제거 할 때주의해야합니다. cellForRow : [셀을 다시 사용하는 경우] –

관련 문제