2010-11-21 7 views
0
선택되었음을있는 tableView 셀 내에서 팝 오버를 표시하려고

UIPopover 판

UITableViewCell *cell; 
UserProfile *switchV = [[UserProfile alloc] initWithNibName:nil bundle:nil]; 
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:switchV]; 
    UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:navController]; 
[pop presentPopoverFromRect:cell.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; 

[switchV 릴리스];

내가 뭘 잘못하고 있니?

+0

질문에 코드를 게시하고 어떤 일이 일어나고 있는지, 어떤 일이 일어나고 있는지를 설명하는 것이 좋습니다. – Anna

+0

나는 그것의 pastie 연결을 배치했다 : – Anthony

+0

이 부호는 didSelectRowAtIndexPath에 있습니까? 셀을 선언했지만 설정하지 않았습니다. – Anna

답변

0

테이블보기 셀에 단추가 있으며 단추를 누를 때 해당 셀을 가리키는 팝업을 표시하려고합니다.

먼저,이 같은 것을 사용 cellForRowAtIndexPath에서 셀에 버튼을 추가

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[button setFrame:CGRectMake(100, 0, 100, 30)]; 
[button setTitle:@"Button" forState:UIControlStateNormal]; 
[button addTarget:self action:@selector(profileUser:) 
         forControlEvents:UIControlEventTouchUpInside]; 
[cell.contentView addSubview:button]; 

위의 중요한 점은 @selector에 있다는 것입니다 (반올림하는 구형 일 필요는 없습니다) profileUser 다음에 콜론이 있습니다.이 단추는 profileUser의 첫 번째 매개 변수로 참조를 보냅니다. 이 참조는 어떤 셀이 선택되었는지 알아내는 데 사용될 수 있습니다.

profileUser :

-(void)profileUser:(UIButton *)button 
{ 
    UITableViewCell *cell = (UITableViewCell *)[[button superview] superview]; 
    //first superview is cell.contentView 
    //second superview is cell 

    UserProfile *switchV = [[UserProfile alloc] initWithNibName:nil bundle:nil]; 
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:switchV]; 
    UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:navController]; 

    [pop presentPopoverFromRect:cell.frame inView:self.view 
     permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

    [switchV release]; 
    [navController release]; 

    self.popoverController = pop; //save in property for later release 

    [pop release]; 
} 

가능하면 UIPopoverArrowDirectionAny의 화살표 방향을두고 그것을 넣어하는 가장 좋은 장소를 알아 보자 방법은 다음과 같이해야한다.

편집 : 화면의 셀의 위치에 따라, 그러나

[pop presentPopoverFromRect:button.frame inView:cell 
    permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; 

:
대신 셀의 단추를 가리키는 화살표와 팝 오버를 표시하려면, 이것을 사용 popover는 버튼 바로 아래를 보지 못할 수도 있습니다. 결과가 확실하지 않은 경우 "Up"대신 "Any"를 사용하십시오.

추후 릴리스 (dealloc)를 위해 popover 컨트롤러에 대한 참조를 저장해야합니다. 그렇지 않으면 메소드의 [pop release]가 충돌을 일으킬 수 있습니다. 자세한 예는 sample app Popovers을 참조하십시오.

+0

안녕하세요, 감사합니다! 이제 단추 프레임을 사용하여 어떻게 표시합니까? 단추 바로 아래에있는 셀에 단추가 있다고 말하십시오. 그 프레임을 사용하려했지만 최신 셀에만 표시되고 다른 셀에는 표시되지 않습니다. – Anthony

+0

답변이 업데이트되었습니다. '최신 셀에 표시되고 다른 셀에 표시되지 않습니다.'라는 의미는 확실하지 않습니다. – Anna

관련 문제