在表格底部添加带有按钮的工具栏的最佳方式



添加不滚动到表格底部的工具栏的最佳方式是什么?

我有一张可供选择的名字表。我希望在屏幕底部有一个工具栏(不一定是UIToolBar),用户可以在其中按下按钮。我希望工具栏总是在那里,而不是随着表格滚动,并且总是在底部。

下面是这个问题的解决方案。

+(void)showToolBar:(UITableView *)tableViewObj
{
    UIView *parentView = tableViewObj.superview;
    CGRect frame, remain;
    CGRectDivide(parentView.bounds, &frame, &remain, 44, CGRectMaxYEdge);
    frame.origin.y = frame.origin.y+5.;
    frame.size.height = frame.size.height-12.;
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:frame];
    [[UIToolbar appearance] setBackgroundColor:[UIColor colorWithRed:(245/255.0) green:(130/255.0) blue:(32/255.0) alpha:1.0]];
    toolbar.barTintColor = [UIColor colorWithRed:(245/255.0) green:(130/255.0) blue:(32/255.0) alpha:1.0];
    toolbar.translucent=NO;
    [toolbar setTintColor:[UIColor whiteColor]];
    UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithTitle:@"Sort" style:UIBarButtonItemStylePlain target:self action:nil];
   // [[UIBarButtonItem appearance] setTitlePositionAdjustment:UIOffsetMake(10, -5) forBarMetrics:UIBarMetricsDefault];
    UIBarButtonItem *spacer  = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    UIBarButtonItem *button2 = [[UIBarButtonItem alloc]initWithTitle:@"Categories" style:UIBarButtonItemStylePlain target:self action:nil];
    UIBarButtonItem *button3 = [[UIBarButtonItem alloc]initWithTitle:@"Filter" style:UIBarButtonItemStylePlain target:self action:nil];
    [toolbar setItems:[[NSArray alloc] initWithObjects:spacer, button1,spacer,button2,spacer,button3, spacer,nil]];
    [toolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
    [tableViewObj.superview addSubview:toolbar];
     //ADD HORIZONTAL LINE BETWEEN BUTTONS
    float x = toolbar.frame.size.width / 3;
     //BUTTON1
    UIView *b1View = [[UIView alloc] initWithFrame:CGRectMake(x-1, 0, 1, 44)];
    b1View.backgroundColor= [UIColor whiteColor];
    [toolbar addSubview:b1View];
    //BUTTON2
    UIView *b2View = [[UIView alloc] initWithFrame:CGRectMake(x*2, 0, 1, 44)];
    b2View.backgroundColor= [UIColor whiteColor];
    [toolbar addSubview:b2View];
}

最新更新