我已经以编程方式将按钮添加到我的视图中,但是当我在模拟器上进行测试时,视图上只有工具栏可见。
我究竟做错了什么?
我在头文件中定义了我的 ui 元素,并在主文件中合成,然后在 viewDidLoad 方法中初始化。但是有一点不对劲。
我的代码如下所示;
#import "ViewController.h"
@implementation ViewController
@synthesize iAmLost, iAmLooking, about, howToUse,appsFromKodAtolye, exit;
- (void)viewDidLoad
{
[super viewDidLoad];
toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0, 320.0, 40.0)];
iAmLost = [[UIButton alloc]initWithFrame:CGRectMake(0,0, 200.0, 10.0)];
iAmLooking = [[UIButton alloc ]initWithFrame:CGRectMake(0, 0, 200.0, 10.0) ];
[iAmLooking addTarget:self
action:@selector(iAmLookingScreen)
forControlEvents:UIControlEventTouchUpInside];
about = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 200.0, 10.0)];
howToUse = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 200.0, 10.0)];
exit = [[UIBarButtonItem alloc] initWithTitle:@"Exit" style:UIBarButtonItemStyleBordered target:self action:@selector(exitApp:)];
NSArray *buttons = [[NSArray alloc]
initWithObjects:exit, nil];
toolbar.items = buttons;
[self.view addSubview:iAmLost];
[self.view addSubview:iAmLooking];
[self.view addSubview:about];
[self.view addSubview:toolbar];
}