UITableView и UIsearchController скрываются под UInavigationBar - PullRequest
0 голосов
/ 11 января 2019

В моем приложении, когда используется searchController и выбран UITableView ... searchController возвращается в NavigationController при возврате в MasterView.

Когда searchController не используется и выбран UITableView ... searchController действует так, как и предполагалось при возврате в masterView.

см. Прикрепленное видео. видео поведения enter image description here

Все представления имеют эти настройки от IB.

вот как я настраиваю контроллер пользователя

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self databaseAddition];
ListString = [NSMutableString string];

store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeReminder
                      completion:^(BOOL granted, NSError *error) {
                          // Handle not being granted permission
                      }];

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(topAction:)];
self.navigationItem.rightBarButtonItem = addButton;


UIBarButtonItem *filterButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(filterAction:)];
self.navigationItem.leftBarButtonItem = filterButton;


self.navigationItem.backBarButtonItem.title = @"Devices";

//instantiate a search results controller for presenting the search/filter results (will be presented on top of the parent table view)
UITableViewController *searchResultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];

searchResultsController.tableView.dataSource = self;

searchResultsController.tableView.delegate = self;


// Create the search controller with this controller displaying the search results
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.dimsBackgroundDuringPresentation = NO;

self.searchController.searchBar.placeholder= @"Search hostname, Tag, Serial, MAC, Model";
self.searchController.hidesNavigationBarDuringPresentation=FALSE;

//self.searchController.searchBar.showsScopeBar=TRUE;
//self.searchController.searchBar.scopeButtonTitles = [NSArray arrayWithObjects:@"All", @"Win7",@"Win10",@"Mac", nil];


self.searchController.searchResultsUpdater = self;
[self.searchController.searchBar sizeToFit];
self.tableView.tableHeaderView = self.searchController.searchBar;
self.tableView.delegate = self;
self.definesPresentationContext = YES;

self.searchController.searchBar.text = query;

//self.navigationItem.leftBarButtonItem = self.editButtonItem;

//UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItem target:self action:@selector(insertNewObject:)];
//self.navigationItem.rightBarButtonItem = addButton;

self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];

[self updateSearchResultsForSearchController:self.searchController];

if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    self.edgesForExtendedLayout = UIRectEdgeNone;}

Ниже приведена функция searchResults

-(void)updateSearchResultsForSearchController:(UISearchController *)searchController {

//get search text from user input

//[NSFetchedResultsController deleteCacheWithName:@"FIVE"];

// Init a fetch request
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];

// Apply an ascending sort for the color items
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"deviceName" ascending:YES selector:@selector(caseInsensitiveCompare:)];
NSArray *descriptors = [NSArray arrayWithObject:sortDescriptor];
[fetchRequest setSortDescriptors:descriptors];

if(AdvSearchON==TRUE)
{
    AdvSearchON=FALSE;

    fetchRequest.predicate = coPredicate;

    NSError *error;

    self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];

    self.fetchedResultsController.delegate = self;


    if (![[self fetchedResultsController] performFetch:&error])    NSLog(@"Error: %@", [error localizedDescription]);

    // Recover query
    query = self.searchController.searchBar.text;
    if (query && query.length) fetchRequest.predicate = [NSPredicate predicateWithFormat:@"deviceName contains[c] %@ or assetTag contains[c] %@ or addressNIC contains[c] %@ or serialNumber contains[c] %@ or model contains[c] %@", query, query, query, query, query];

    // Init the fetched results controller
    NSError *error;

    self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];

    self.fetchedResultsController.delegate = self;


    if (![[self fetchedResultsController] performFetch:&error])    NSLog(@"Error: %@", [error localizedDescription]);
}

//now that the tableSections and tableSectionsAndItems properties are updated, reload the UISearchController's tableview
[self.tableView reloadData];

NSString *TitleCount = [NSString stringWithFormat:@"%lu Devices", [self.fetchedResultsController.fetchedObjects count]];
self.title = TitleCount;NSLog(@"Table code count hit...");}
...