首页 > 弹窗窗口无法在最前面显示,被searchbar 和navigation bar挡住了

弹窗窗口无法在最前面显示,被searchbar 和navigation bar挡住了

根据《The iOS Apprentice》的资料学习iOS,在学习第4个应用“StoreSearch”的“The Detail pop-up”章节时候,遇到了一个问题。
编写的pop-up的controller view无法无法在最前面显示,被searchbar 和navigation bar挡住了。

使用的主要代码如下:


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.searchBar resignFirstResponder];
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    DetailViewController1 *controller = [[DetailViewController1 alloc] initWithNibName:@"DetailViewController1" bundle:nil];
    
//    controller.view.frame = self.view.bounds;
    controller.view.frame = CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y - 108, self.view.bounds.size.width, self.view.bounds.size.height);
    [self.tableView addSubview:controller.view];
    [self addChildViewController:controller];
    [controller didMoveToParentViewController:self];
}

对比了教材中的源代码,没有发现不同之处。。。
请问应该如何解决?多谢。

另外一个问题是,弹出的View会随着tableview的滑动而滑动,如下图所示:

目前代码已经放在了github上面 StoreSearch,多谢。

更新:
通过Xcode的debug工具对比了一下示例程序和自己的程序,发现UI的层次不同,如下图所示:
示例程序:

我的程序:

从图片中可以看出,poped up的UIView(GradientView)的层次不同,正确的应该和UISearchBar在同一级。

然后赶紧仔细检查了一下相关代码,发现在“didSelectRowAtIndexPath”中,添加popedView的时候,将[self.view addSubview:controller.view];错误的写成了[self.tableview addSubview:controller.view];,所以才导致了错误的发生。

现在问题解决,多谢大家。


问题已经解决,UIViewController的层次搞错了。

【热门文章】
【热门文章】