gpt4 book ai didi

objective-c - 尝试使用 2 个 UIButtons 创建 View 时出现错误

转载 作者:行者123 更新时间:2023-11-29 05:05:09 24 4
gpt4 key购买 nike

我正在尝试创建一个带有两个 UIButton 的 View 。代码编译没有任何错误,但按钮没有任何标签,无法单击。 enter image description here

-(id)initWithTabBar {

if ([self init]) {
self.title = @"Tab1";
self.tabBarItem.image = [UIImage imageNamed:@"promoters.png"];
self.navigationItem.title = @"Nav 1";
}

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"Button" forState:UIControlStateNormal];
[button addTarget:self action:@selector(facebookAuthorize) forControlEvents:UIControlEventTouchDown];
[button setFrame:CGRectMake(10, 10, 100, 100)];

[self.view addSubview:button];

[button release];

UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button2 setTitle:@"Button" forState:UIControlStateNormal];
[button2 addTarget:self action:@selector(facebookLogin) forControlEvents:UIControlEventTouchDown];
[button2 setFrame:CGRectMake(110, 10, 100, 100)];

[self.view addSubview:button2];

[button2 release];

return self;
}

最佳答案

不要松开这些按钮。它们被创建为自动释放的对象。如 documentation 中所述:

You only release or autorelease objects you own. You take ownership of an object if you create it using a method whose name begins with “alloc”, “new”, “copy”, or “mutableCopy”

这些单词都不会出现在 buttonWithType: 中,因此您无需承担责任,并且可以放心地假设它是自动释放的。

关于objective-c - 尝试使用 2 个 UIButtons 创建 View 时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5681952/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com