我正在尋找創建一個酒吧,只有在狀態欄下的iPhone界面頂部的幾個按鈕,控制器是一個簡單的UIViewController,所以這是一個不用於導航的按鈕欄。我已經有了一些工作,但感覺有點笨拙,我想知道我是否做得對,並且沒有錯過任何捷徑。獨立的UINavigationBar?
- 有沒有行動/選擇器:設置,因爲我只是設置它。
- 我可能會刪除NSArray便捷方法並添加一個alloc/release。
代碼:
- (void)loadView {
// VIEW
UIView *tempView = [[UIView alloc] initWithFrame:screenFrame];
// NAV BAR
UINavigationBar *tempNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[tempNavigationBar setBarStyle:UIBarStyleBlack];
UIBarButtonItem *testButton = [[UIBarButtonItem alloc] initWithTitle:@"TEST" style:UIBarButtonItemStyleBordered target:self action:nil];
UINavigationItem *navItem = [[UINavigationItem alloc] init];
[navItem setLeftBarButtonItem:testButton];
[testButton release];
[tempNavigationBar setItems:[NSArray arrayWithObject:navItem]];
[tempView addSubview:tempNavigationBar];
[tempNavigationBar release];
[navItem release];
[self setView:tempView];
[tempView release];
}
你沒有使用Interface Builder的原因?我認爲所有這些代碼都可以從IB完成。 – 2011-02-02 19:04:07
爲了保持真實,我通常會使用interfaceBuilder,但是這次我試圖以編程方式做事情,希望能夠更好地理解事情的工作原理。特別對於一個新用戶來說,儘管IB非常有用並且功能強大,但它確實隱藏/抽象了一些有助於理解的內容。 – fuzzygoat 2011-02-02 19:25:36