尝试使用2个UIButton创建视图时发生错误

| 我正在尝试使用两个UIButton创建一个视图。代码可以编译,没有任何错误,但是按钮没有任何标签,因此无法单击它们。
-(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;
}
    
已邀请:
不要释放这些按钮。它们被创建为自动发布的对象。如文档中所述:   您只释放或自动释放   您拥有的对象。您拥有   如果您使用   名称以“ alloc”开头的方法,   “新”,“副本”或“ mutableCopy” 这些单词都不会出现在buttonWithType:中,因此您无需承担责任,可以放心地假定它是自动发布的。     
如前所述,按钮的withType不能命名。使单词出现在uibutton中的代码是:
  UIButton *someButton=[[[UIButton alloc]initWithFrame:CGRectMake(140, 6, 175, 36)]autorelease];
[someButton addTarget:self action:@selector(facebookLogin) forControlEvents:UIControlEventTouchDown];
[someButton setTitle:@\"Button\" forState:UIControlStateNormal];
[self.view addSubview:someButton];
    

要回复问题请先登录注册