我搜索了所有的互联网,似乎每个关于这个主题的帖子都遗漏了我需要的一条重要信息.无论人们告诉我做什么,我都无法摆脱关于我的按钮操作方法的所有/任何事情的"未声明的标识符"错误.我已经选择了这么多的代码,以至于它完全被顶起来了.任何人都可以告诉我我需要做什么才能做出正确的互动按钮?用于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.");
}
Run Code Online (Sandbox Code Playgroud)
而问题并不在于它运行,然后崩溃,问题是,我不能运行它,只要开始,因为我有这个错误"使用未声明的标识符的'amethod方法’"
请试试这段代码
UIButton *submitButton=[[UIButton alloc]initWithFrame:CGRectMake(120, 300, 70, 50)];
[submitButton.layer setCornerRadius:10.0];
[submitButton setTitle:@"Submit" forState:UIControlStateNormal];
[submitButton addTarget:self action:@selector(submitAction:)forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:submitButton];
Run Code Online (Sandbox Code Playgroud)
.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.");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
285 次 |
| 最近记录: |