Chaudhry Talha
Chaudhry Talha

Reputation: 7868

UISearchController change width when editing starts

I'm presenting my tableViewController in KGModal. In my viewDidLoad I've added these few properties to manage 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;

Whereas setupSearchController is

-(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;
}

Now when I run the app it show me searchController as

enter image description here

Which is fine and exactly what I'm looking for. But as soon as it became the first responder this happens:

enter image description here

By Cancelling it makes it go back to the position it is in the first picture. My question is how to make it stay inside the frame of KGModal. Where as I'm calling it as

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
By following one of the solutions given here I've been able to keep it inside the height but not the width of view. enter image description here
I just updated the code in VIewDidLoad as

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

Upvotes: 0

Views: 412

Answers (1)

Anbu.Karthik
Anbu.Karthik

Reputation: 82759

change the frame and check once

change this line

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

to this

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

for updated answer

-(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];
}

Upvotes: 1

Related Questions