我在KGModal中展示了我的tableViewController
。
在我的viewDidLoad
中,我添加了这几个属性来管理tableView:
[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为
这很好,正是我正在寻找的。但是一旦它成为第一个响应者,就会发生这种情况:
通过取消它使它回到它在第一张图片中的位置。我的问题是如何让它留在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];
的更新
通过遵循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 :(得分: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];
}