2015-01-09 5 views
1

viewController Category가 있고 해당 범주에 UILabel이 있습니다. 다른 viewController에서 레이블 제목을 설정하고 싶습니다.UIViewController에서 레이블 제목 설정

충돌이 발생했을 때.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[BaseViewController setTitleLabel:]: unrecognized selector sent to instance 0x7fcfe857a580' 

어떻게하면됩니까?

편집 :

TitleLabel 여기, 카테고리에서 레이블의 UIViewController 카테고리의 코드입니다

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 
    btn.frame = CGRectMake(0, 0, 50, 50); 
    [btn setImage:[UIImage imageNamed:@"Menu"] forState:UIControlStateNormal]; 
    [btn addTarget:self action:@selector(MenuPressed:) forControlEvents:UIControlEventTouchUpInside]; 
    UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc]initWithCustomView:btn]; 

    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom]; 
    btn1.frame = CGRectMake(0, 0, 70, 44); 
    [btn1 setTitle:@"Clickme!" forState:UIControlStateNormal]; 
    btn1.backgroundColor = [UIColor blueColor]; 


    UILabel *titleLabel = [UILabel new]; 
    titleLabel.frame = CGRectMake(0, 0, 100, 44); 
    titleLabel.backgroundColor =[UIColor cyanColor]; 

    UIBarButtonItem *barBtn2 = [[UIBarButtonItem alloc]initWithCustomView:btn1]; 
    UIBarButtonItem *barTitle = [[UIBarButtonItem alloc]initWithCustomView:titleLabel]; 
    UIBarButtonItem *flexibleItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; 

    NSArray *barBtnArray = @[leftBtn,flexibleItem,barTitle,barBtn2]; 
    self.navigationItem.leftBarButtonItems = barBtnArray; 

답변

0

당신이 할 수있는 레이블 속성은 .m 파일에 선언되어 있기 때문이다. 외부에 액세스 할 수 없으므로 액세스하려고하면 충돌합니다 (개인 소유물과 같은 것입니다). 이 문제를 해결할 수있는 2 가지 방법이 있습니다.

옵션 1

.h 파일에 선언 label 속성 자체

옵션 2

는 인수의 같은 NSString 소요의 값으로 설정하는 public 메소드를 작성하여 상표.

0

UIViewController에는 titleLabel 속성이 없습니다. 카테고리 클래스를 확인하십시오.

+0

titleLabel은 카테고리의 라벨로 내 편집을 확인합니다. –

+0

문제를 파악할 수 있도록 코드를 더 게시 할 수 있습니까? – abhishekkharwar

+0

UIViewcontroller 카테고리에서 레이블 코드를 추가했습니다. –