2016-10-04 75 views
0

我提出我tableViewControllerKGModal。 在我viewDidLoad我已經添加了這幾個屬性來管理的tableView:編輯時UISearchController變動幅度開始

[self setupSearchController]; 
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; 
self.tableView.tableHeaderView = self.searchController.searchBar; 
self.edgesForExtendedLayout = UIRectEdgeNone; 
self.definesPresentationContext = NO; 
self.view.clipsToBounds = YES; 

setupSearchController

-(void)setupSearchController 
{ 
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil]; 
    self.searchController.searchResultsUpdater = self; 
    self.searchController.dimsBackgroundDuringPresentation = NO; 
    self.searchController.hidesNavigationBarDuringPresentation = NO; 
    // self.searchController.searchBar.scopeButtonTitles = @[NSLocalizedString(@"ScopeButtonCountry",@"Country"), NSLocalizedString(@"ScopeButtonCapital",@"Capital")]; 
    // self.searchController.searchBar.clipsToBounds = YES; 
    self.searchController.searchBar.delegate = self; 
} 

現在,當我運行程序的時候,告訴我searchController爲

enter image description here

這很好,我正在尋找。但只要它成爲第一個響應者,就會發生這種情況:

enter image description here

通過取消它使其返回到它在第一張圖片中的位置。我的問題是如何讓它保持在KGModal的框架內。凡爲我叫它爲

CPTSearchTableViewController *ivc = [self.storyboard instantiateViewControllerWithIdentifier:@"CPTSearchTVC"]; 
    ivc.view.frame = CGRectMake(0, 0, CGRectGetWidth([[UIScreen mainScreen] bounds]) - 40, CGRectGetHeight([[UIScreen mainScreen] bounds]) - 80); 
    [[KGModal sharedInstance] setCloseButtonType:KGModalCloseButtonTypeRight]; 
    [[KGModal sharedInstance] showWithContentViewController:ivc andAnimated:YES]; 
    [[KGModal sharedInstance] setTapOutsideToDismiss:YES]; 
    [[KGModal sharedInstance] setModalBackgroundColor:[UIColor clearColor]]; 
    [[KGModal sharedInstance] setBackgroundDisplayStyle:KGModalBackgroundDisplayStyleSolid]; 


UPDATE
通過以下給出here的解決方案,我已經能夠保持它的高度內的一個而不是來看寬度。 enter image description here
我剛剛更新在viewDidLoad中的代碼爲

[self setupSearchController]; 
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; 
    self.tableView.tableHeaderView = self.searchController.searchBar; 
    self.edgesForExtendedLayout = UIRectEdgeNone; 
    self.definesPresentationContext = YES; 
    self.extendedLayoutIncludesOpaqueBars = YES; 
+0

http://stackoverflow.com/questions/26222671/uisearchcontroller-searchbar-in-tableheaderview-animating-out-of-the-screen?rq=1你試圖回答這些問題? –

+0

@HannahLouisaCarney看到我更新的問題 –

+0

您可以將您的projct這裏 –

回答

1

變化框架和檢查一次

改變這一行更新

//[[KGModal sharedInstance] showWithContentViewController:ivc andAnimated:YES]; 

這個

[[KGModal sharedInstance] showWithContentView:ivc.view andAnimated:YES]; 

回答

-(void)showTableView 
{ 
SampleTableViewController *ivc = [self.storyboard instantiateViewControllerWithIdentifier:@"SampleVC"]; 
//ivc.delegate = self; 
ivc.view.frame = CGRectMake(0, 0, CGRectGetWidth([[UIScreen mainScreen] bounds]) - 40, CGRectGetHeight([[UIScreen mainScreen] bounds]) - 80); 
[[KGModal sharedInstance] setCloseButtonType:KGModalCloseButtonTypeRight]; 
[[KGModal sharedInstance] setTapOutsideToDismiss:NO]; 
//[[KGModal sharedInstance] showWithContentViewController:ivc andAnimated:YES]; 
[[KGModal sharedInstance] showWithContentView:ivc.view andAnimated:YES]; 
[[KGModal sharedInstance] setTapOutsideToDismiss:YES]; 
// [[KGModal sharedInstance] setModalBackgroundColor:[UIColor clearColor]]; 
[[KGModal sharedInstance] setBackgroundDisplayStyle:KGModalBackgroundDisplayStyleSolid]; 
} 
+0

'setupSearchController'它沒有工作!昨天,當我將'self.definesPresentationContext'從'NO'改爲'YES'時,問題的更新部分發生了。意味着Y保持不變,但X會改變。 –

+0

@TalhaCh - 雅我也想的一樣,問題是當你目前的鍵盤是正確的,如果附加projct我會檢查,並告訴到u –

+0

@TalhaCh - 確定下載超過 –