我搜索了所有互联网,似乎有关该主题的每篇帖子都遗漏了我需要的重要信息。无论别人告诉我怎么做,我都无法摆脱与按钮操作方法有关的所有错误。我选择了如此多的代码,以至于它完全无法使用。谁能告诉我我需要做一个正确的交互式按钮吗? .m文件和.h文件中用于viewcontroller的所有内容?请不要以为我已经有了一些重要的代码,因为我可能没有。我是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.");
    }

关于ios - 我无法以编程方式创建UIButton,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21871691/

10-15 14:09
查看更多