开发者社区 问答 正文

UIButton-编程创建问题

编程创建了UIButton:

- (void)viewDidLoad
{
    [paymentsHomeView setFrame:CGRectMake(0, 0, 320, 520)]; // paymentsHomeView is added and referenced in IB

    UIButton *paymentButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 45, 300, 41)];
    paymentButton.titleLabel.text = @"Button";
    paymentButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [paymentButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.paymentsHomeView addSubview:paymentButton];

    [super viewDidLoad];
}

-(void) buttonClicked {

    NSLog(@"buttonClicked");
}

什么也没输出,Button没创建成功。

但是同样方法创建UITextField就成功了。

展开
收起
爵霸 2016-05-27 10:39:31 2007 分享 版权
0 条回答
写回答
取消 提交回答
问答地址: