带有UIToolbar的嵌入式UITableView的UIView Modal Popup,工具栏随表移动

时间:2012-11-26 23:09:07

标签: objective-c ios xcode interface-builder storyboard

这让我疯了! (ios 5 +,ARC)

这里非常简单的概念: 我有UIView嵌入式UITableView,当点击特定单元格时,我让iOS启动带有segue的modalview。 此modalviewUIView,其中包含嵌入式UITableView,其中包含来自数据源的名称。您可以在此视图中选择多个项目(使用cellaccessory: checkmark)

目标 获取某种“完成”按钮以显示

好的,所以经过多次运行后,我明白Modal窗口实际上不允许navigationController个项目。默认情况下,没有toolbars,没有Navigationbars。 好的,所以我会创建自己的。

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSInteger tbHeight = 50;
    UIToolbar *tb = [[UIToolbar alloc] initWithFrame:CGRectMake(0, (self.view.frame.size.height - tbHeight), self.view.frame.size.width, tbHeight)];
    tb.translucent = YES;

    UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(doneAction:)];

    NSArray *barButton  =   [[NSArray alloc] initWithObjects:flexibleSpace,doneButton,nil];
    [tb setItems:barButton];


    [self.view addSubview:tb];

    barButton = nil;

    //....

}

够简单吧?

嗯,toolbar确实出现了。但是,它并没有像它应该的那样坚持到底部。事实上,当您向上和向下滚动嵌入式tableview时,UIToolbar会随之而来,就像它以某种方式卡在tablevie上一样。

我一直在寻找解决方案的时间,我什么都没发现。想知道这里有人有什么想法吗?

如果您需要更多信息,请务必查询:)

1 个答案:

答案 0 :(得分:1)

奇怪的是,如果你的工具栏是一个UIViewController子类,你的工具栏就会滚动它,除非你已经为自己。或者其他东西分配了一个UITableView ......但是既然如此,这就是我的工作将固定项添加到表视图中:

-(void) scrollViewDidScroll:(UIScrollView *)scrollView {

    tb.frame = CGRectMake(0, self.view.bounds.size.height-tb.bounds.size.height+scrollView.contentOffset.y, self.view.bounds.size.width, tb.bounds.size.height);

}