我有一个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类别的标签代码。 –