为什么我的UIButton没有出现?

时间:2011-03-11 23:15:30

标签: iphone objective-c uibutton

这是我正在使用的代码:

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(100, 200, 50, 70)];
    [self.view addSubview:button];
    if (buttonArray == nil) {
        buttonArray = [[NSMutableArray alloc] init];
    }
    [buttonArray addObject:button];
    [button release];
但是,

没有显示对接。有什么想法吗?

1 个答案:

答案 0 :(得分:8)

你错误地初始化了。请尝试以下方法:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(100, 200, 50, 70);
[self.view addSubview:button];
if (buttonArray == nil) {
    buttonArray = [[NSMutableArray alloc] init];
}
[buttonArray addObject:button];