搜尋

首頁  >  問答  >  主體

objective-c - 彈跳視窗無法在最前面顯示,被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. ];,所以才導致了錯誤的發生。

現在問題解決,多謝大家。

某草草某草草2865 天前670

全部回覆(1)我來回復

  • 怪我咯

    怪我咯2017-05-02 09:21:02

    問題已經解決,UIViewController的層次搞錯了。

    回覆
    0
  • 取消回覆