gpt4 book ai didi

ios - NSInvalidArgumentException',原因 : '-[UILabel view]: unrecognized selector sent to instance 0x7ffbd0da2680'

转载 作者:行者123 更新时间:2023-11-29 01:39:38 24 4
gpt4 key购买 nike

下面是我收到此错误的代码。

UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, self.view.bounds.size.height - 44.0f, self.view.bounds.size.width, 44.0f)];
toolBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
[self.view addSubview:toolBar];
UIBarButtonItem *people = [[UIBarButtonItem alloc] initWithTitle:@"people" style:UIBarButtonItemStylePlain target:self action:@selector(tap:)];
UIBarButtonItem *food = [[UIBarButtonItem alloc] initWithTitle:@"food" style:UIBarButtonItemStylePlain target:self action:@selector(tap:)];
UIBarButtonItem *nature = [[UIBarButtonItem alloc] initWithTitle:@"nature" style:UIBarButtonItemStylePlain target:self action:@selector(tap:)];
UIBarButtonItem *sports = [[UIBarButtonItem alloc] initWithTitle:@"sports" style:UIBarButtonItemStylePlain target:self action:@selector(tap:)];
UIBarButtonItem *cats = [[UIBarButtonItem alloc] initWithTitle:@"cats" style:UIBarButtonItemStylePlain target:self action:@selector(tap:)];
UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UILabel *lbl1 = [[UILabel alloc] init];
[lbl1 setFrame:CGRectMake(0,5,100,20)];
lbl1.backgroundColor=[UIColor clearColor];
lbl1.textColor=[UIColor whiteColor];
lbl1.userInteractionEnabled=YES;
[self.view addSubview:lbl1];
lbl1.text= @"TEST";
[toolBar setItems:@[space, lbl1, people, food, nature, sports, cats, space]];

最佳答案

你的错误在这一行,因为你在工具栏中添加了标签。使用此代码

UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, self.view.bounds.size.height - 44.0f, self.view.bounds.size.width, 44.0f)];
toolBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
[self.view addSubview:toolBar];
UIBarButtonItem *people = [[UIBarButtonItem alloc] initWithTitle:@"people" style:UIBarButtonItemStylePlain target:self action:@selector(tap:)];
UIBarButtonItem *food = [[UIBarButtonItem alloc] initWithTitle:@"food" style:UIBarButtonItemStylePlain target:self action:@selector(tap:)];
UIBarButtonItem *nature = [[UIBarButtonItem alloc] initWithTitle:@"nature" style:UIBarButtonItemStylePlain target:self action:@selector(tap:)];
UIBarButtonItem *sports = [[UIBarButtonItem alloc] initWithTitle:@"sports" style:UIBarButtonItemStylePlain target:self action:@selector(tap:)];
UIBarButtonItem *cats = [[UIBarButtonItem alloc] initWithTitle:@"cats" style:UIBarButtonItemStylePlain target:self action:@selector(tap:)];
UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
lbl1 = [[UILabel alloc] init];
[lbl1 setFrame:CGRectMake(0,64,100,20)];
lbl1.backgroundColor=[UIColor clearColor];
lbl1.textColor=[UIColor redColor];
lbl1.userInteractionEnabled=YES;
[self.view addSubview:lbl1];
lbl1.text= @"TEST";
[toolBar setItems:@[space, people, food, nature, sports, cats, space]];

工具栏项点击事件

-(IBAction)tap:(UIBarButtonItem*)sender{
lbl1.text= sender.title;
}

关于ios - NSInvalidArgumentException',原因 : '-[UILabel view]: unrecognized selector sent to instance 0x7ffbd0da2680' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32557456/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com