2013-07-06 2 views
0

내 사용자 지정 메뉴에서 하위 컨트롤러 인 주 컨트롤러로 뷰 컨트롤러를 푸시 할 수 있고 위임을 사용하여 수행하려고합니다. 내가보기 컨트롤러를 바꾸려고 시도하기 전에, 현재보기 컨트롤러 제목을 변경하기 위해 좀 더 쉽게갔습니다. 이것은 내가 지금까지 작성한 코드이지만 TableView 셀을 테이핑하면 델리게이트가 트리거되지 않습니다.메뉴에서 뷰를 변경하는 대리자 만들기

@protocol SlidingMenuDelegate <NSObject> 

@end 

@interface SlideMenuViewController : UIViewController 
{ 
     id <SlidingMenuDelegate> delegate; 
} 
@property (strong, nonatomic) id delegate; 

SlideMenuViewController.m :

알려 주시기 바랍니다

    -> RootViewController 
       /     \ 
      Container    Container  
       |       | 
    SlideMenuViewController  SubClassed UINavigationController 
       |       | | | | 
    UITableViewController    VC1 VC2 VC3 VC4 


SlideMenuViewController.h (또는 그렇게 보인다)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    //do something to send controller 

    ((UIRTLNavigationController *)(self.delegate)).titleForView.text = @"test"; 
} 

MyNavigationController.h :

@interface MyNavigationController : UINavigationController <UINavigationControllerDelegate> 

@property (nonatomic, strong) UILabel *titleForView; 

MyNavigationController.m는 :

- (void)showRightMenu 
{ 
... 
... 
//Some animation to slide the menu out 

    //Delegate stuff 
    //Get the storyboard's instance. 
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]]; 

    SlideMenuViewController *slideMenuVC; 

    //Get the viewcontrollers instance from the storyboard's instance 
    slideMenuVC = [storyBoard instantiateViewControllerWithIdentifier:@"slideMenuSID"]; 
    slideMenuVC.delegate = self; 
} 
+0

위임자는 어디에 설정되어 있습니까? 프로토콜에 메소드 정의가없는 이유는 무엇입니까? 델리게이트 속성은 대개 '강'하지 않아야합니다. 테이블 셀을 선택하면 디버깅하거나 일부 로깅 코드를 추가하여이를 확인하십시오. – Wain

답변

0

귀하의 SlidingMenuDelegate 프로토콜은 slidingMenu:didSelectOption: 같은 일부 (옵션) 방법을 필요로한다. 또한 열거 형 또는 메뉴가 제공하는 모든 옵션을 지정하는 것을 정의 할 것입니다.

는 그런 다음 tableView:didSelectRowAtIndexPath: 방법, 당신은 마지막으로,이 slidingMenu:didSelectOption: 메시지에 대한 응답으로 뭔가를 할 것이다 대리인 (예를 들어 네비게이션 컨트롤러의 제목을 설정)

if ([self.delegate respondsToSelector:@selector(slidingMenu:didSelectOption:)]) { 
    SlidingMenuOption option; 

    switch (indexPath.row) { 
    case 0: 
     option = SlidingMenuFooOption; 
     break; 

    case 1: 
     option = SlidingMenuBarOption; 
     break; 

    // ... 
    } 

    [self.delegate slidingMenu:self didSelectOption:option]; 
} 

할 것입니다.

관련 문제