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