2013-07-11 3 views
0

!!! 예, 멍청한 질문입니다. 그렇습니다.다른 파일에서 UINavigationController에 액세스

그래서 테이블 뷰가있는 file1에 탐색 컨트롤러를 만들었습니다. 해당 테이블보기의 셀은 다른 클래스와 xib (file2)를 갖는 사용자 정의 셀입니다. file2 xib에는 클릭이있을 때 탐색 컨트롤러에보기를 밀어 넣어야하는 단추가 있습니다.

이제 file2에서 file1에서 만든 탐색 컨트롤러를 참조하는 방법을 알지 못합니다.

편집 : AppDelegate에서 내비게이션 컨트롤러를 설정하고 공유 위임자를 만들면이 문제가 해결되었지만 file1에서 내비게이션 컨트롤러를 설정하려면 어떻게해야합니까?

답변

0

이 경우 나는 파일 2delegate이있는 것을 선호합니다. u는 delegateself로를 설정해야 파일 1CustomCell 객체를 생성 할 때

.H 파일을 볼 수 있었다 다음이

#import <Foundation/Foundation.h> 

@protocol CustomCellDelegate <NSObject> 
- (void)buttonClicked; 
@end 

@interface CustomCell : UITableViewCell 

@property (nonatomic, weak) id<CustomCellDelegate> delegate; 

- (void)getImageWithCompletionHandler:(handler)completionBlock; 

@end 

과 같은합니다.

CustomCell *customCell = … 
…. 
customCell.delegate = self; 

CustomCellDelegate 에 FILE1

- (void)buttonClicked 
{ 
    // TODO: push using navigation controller code. 
} 

는 상기 위임 패턴 구현이다. MVC (모델 뷰 컨트롤러)에 의하면 가이드 here

더 많은 약 delegates 수표 패턴 뷰의 작업은 밀 또는 다른 제어기를 표시하는 데이터 및 제어기 작업을 표시 할 수있다.

희망이 있습니다.

관련 문제