我搜索了所有互联网,似乎有关该主题的每篇帖子都遗漏了我需要的一项至关重要的信息。无论别人告诉我怎么做,我都无法摆脱与按钮操作方法有关的所有内容/“未声明的标识符”错误。我对代码的选择太多了,以至于完全无法理解。谁能告诉我我需要做一个正确的交互式按钮吗?ViewController的.m文件和.h文件中包含的所有内容?
请不要以为我已经掌握了一些至关重要的代码,因为我可能没有。我是Objective-C的新手。
谢谢!!!!!!!!(顺便说一句,这是为ipad设计的,我避免使用情节提要)谢谢!在这一点上,我感到非常沮丧。
到目前为止,这是我的代码
UIButton *add = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[add addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchDown];
[add setTitle:@"add new" forState:UIControlStateNormal];
add.frame = CGRectMake(100, 100, 100, 100);
[objects addSubview:add];
- (void)aMethod:(UIButton*)button
{
NSLog(@"Button clicked.");
}
问题不是它先运行然后崩溃,问题是只要我遇到此错误“使用未声明的标识符'aMethod'”,我就无法运行它。
.what is object in this line [object addSubview:add];
try this
UIButton *add = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[add addTarget:self action:@selector(aMethod) forControlEvents:UIControlEventTouchDown];
[add setTitle:@"add new" forState:UIControlStateNormal];
add.frame = CGRectMake(100, 100, 100, 100);
[object addSubview:add];
- (void)aMethod
{
NSLog(@"Button clicked.");
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句