我有一個viewController類別和在類別中有一個UILabel。 我想從另一個viewController設置標籤標題。從UIViewController設置標籤標題
當我試圖崩潰。
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[BaseViewController setTitleLabel:]: unrecognized selector sent to instance 0x7fcfe857a580'
我該如何做到這一點。
編輯:
TitleLabel
是A類標籤,這裏是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;
titleLabel是類別中的標籤檢查我的編輯; –
你可以發佈一些更多的代碼,所以我們可以找出問題。 – abhishekkharwar
我已經添加了UIViewcontroller類別的標籤代碼。 –