2009-05-01 73 views
2

我在嘗試構建自己的視圖時遇到了一些困難。一切都很好,直到我需要將UIToolBar插入到視圖中。 tableView放置在我預期放置的位置。另一方面,UIToolBar與表格一起上下滾動,但它不會像應該那樣保持固定。當放在屏幕上時它看起來很奇怪 - 我猜測是因爲計算放置它不正確?附加到這個問題是一個截圖,以及我用來構建這個的代碼。感謝您的幫助,發現我做錯了什麼。截圖:http://dl-web.dropbox.com/u/57676/screenshots/broketoolbar.png爲什麼我的UIToolBar使用我的UITableView滾動?

代碼:

- (void)loadView 
{ 
    [super loadView]; 
    // TableViews that wish to utilize tableView footers/headers should override this method. 

    UITableView *aTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain]; 
    aTableView.autoresizingMask = (UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight); 
    aTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; 

    aTableView.delegate = self; 
    aTableView.dataSource = dataSource; 

    self.tableView = aTableView; 
    self.view = tableView; 
    [aTableView release]; 

    UIToolbar *toolbar = [UIToolbar new]; 
    [toolbar setBarStyle:UIBarStyleBlackOpaque]; 
    [toolbar sizeToFit]; 
    CGFloat toolbarHeight = [toolbar frame].size.height; 
    CGRect mainViewBounds = self.view.bounds; 
    [toolbar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds), 
           CGRectGetMinY(mainViewBounds) + CGRectGetHeight(mainViewBounds) - (toolbarHeight * 2.0), 
           CGRectGetWidth(mainViewBounds), 
           toolbarHeight)]; 
    [self.view insertSubview:toolbar aboveSubview:self.tableView]; 
    [toolbar release]; 
}        

回答

2

因爲self.view是的tableView在其中添加工具欄。

相關問題