Iphone 为什么我的UIToolBar与我的UITableView一起滚动?

Iphone 为什么我的UIToolBar与我的UITableView一起滚动?,iphone,cocoa-touch,objective-c,Iphone,Cocoa Touch,Objective C,我在尝试建立自己的观点时遇到了一些困难。当我需要在视图中插入UIToolBar时,一切都很顺利。tableView被放置在我期望的位置。另一方面,UIToolBar会随着表格上下滚动,它不会保持固定不变。当它出现在屏幕上时,看起来也很奇怪——我猜是因为放置它的计算不正确?这个问题附带了一个屏幕截图以及我用来构建这个问题的代码。谢谢你帮我发现我做的不对。截图: 守则: - (void)loadView { [super loadView]; // TableViews that w

我在尝试建立自己的观点时遇到了一些困难。当我需要在视图中插入UIToolBar时,一切都很顺利。tableView被放置在我期望的位置。另一方面,UIToolBar会随着表格上下滚动,它不会保持固定不变。当它出现在屏幕上时,看起来也很奇怪——我猜是因为放置它的计算不正确?这个问题附带了一个屏幕截图以及我用来构建这个问题的代码。谢谢你帮我发现我做的不对。截图:

守则:

- (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];
}                            

因为self.view是您添加工具栏的tableView