Darren
Darren

Reputation: 1712

Can't stop navigation bar covering pushed view - why is it happening?

That eureka moment has well and truly eluded me with this problem. I have created a NavigationController in code. Attached a rootviewcontroller, which creates a tableview (also in code). This is all working as expected. The tableview presents, sliding in from the right etc options load etc.

When I then select an option in this first tableview to load a UIView (without a table just some images) this is what I'm getting (ahhhh ... can't show as I need 10 reputation to post images apparently ... sigh!).

Anyways, the view is being pushed from the right. However the content of the view is being masked (in part) by the navigation bar. It's too high up.

The code I have used to create this problem is shown below:

SearchMainTableViewController.h

#import <UIKit/UIKit.h>
#import "CRPSearchMainTableViewController.h"

@interface CRPSearchMasterViewController : UINavigationController

@property (strong, nonatomic) UINavigationController *myNavigationController;
@property (strong, nonatomic) CRPSearchMainTableViewController *myMainTableViewController;

@end

SearchMainTableViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    _myMainTableViewController = [[CRPSearchMainTableViewController alloc] initWithNibName:nil bundle:nil];
    myNavigationController = [[UINavigationController alloc] initWithRootViewController:_myMainTableViewController];

    [self.view addSubview:myNavigationController.view];
}

In my SearchMainTableViewController I have:

#import "CRPRegistrationMasterViewController.h"
#import "CRPFixedSearchViewController.h"
#import "CRPSettingsPickerViewController.h"

@interface CRPSearchMainTableViewController : CRPRegistrationMasterViewController <UITableViewDataSource, UITableViewDelegate>

@property (strong, nonatomic) UITableView *myTableView;
@property (strong, nonatomic) CRPFixedSearchViewController *myFixed;
@property (strong, nonatomic) CRPSettingsPickerViewController *mySettingsPicker;

@end

And sections of the SearchMainTableViewController.m:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"Settings";
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(loadNext)];

    myTableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    myTableView.delegate = self;
    myTableView.dataSource = self;
    [myTableView registerNib:[UINib nibWithNibName:@"settingsTableCell" bundle:nil] forCellReuseIdentifier:tableCell];

    myParams = [self getSearchParams];
    if (myParams){
        NSLog(@"I have params");
    } else {
        NSLog(@"I don't have params");
        // First time of running this
        SearchParams *params = [NSEntityDescription insertNewObjectForEntityForName:@"SearchParams" inManagedObjectContext:_myManagedObjectContext];
        if (params != nil)
        {
            NSError *paramsError = nil;
            if ([_myManagedObjectContext save:&paramsError])
            {
                NSLog(@"I have added a SearchParams field in the table");
            } else {
                NSLog(@"I have a problem with adding Search Params into the table: %@", [paramsError userInfo]);
            }
        } else {
            NSLog(@"Cannot get entity");
        }
    }

    [self.view addSubview:myTableView];

}

...

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    switch (indexPath.row) {
    case 2:
    {
        mySettingsPicker = [[CRPSettingsPickerViewController alloc] initWithNibName:@"SettingsPicker" bundle:nil];
        [self.navigationController pushViewController:mySettingsPicker animated:YES];

    }
        break;

CRPSettingsPickerViewController is a simple controller. I've added no code. I just wished to see if the view would load properly (which I can't show as I don't have a reputation of 10 sigh).

Any help would be great. I have a feeling I'm missing something small. All the problems I have faced with any project have revolved around TableViews. They are my nemesis it would appear.

Cheers

Upvotes: 3

Views: 699

Answers (2)

Ken
Ken

Reputation: 31161

Take a another look at the edgesForExtendedLayout property of a UIViewController introduced with iOS 7. The default value is UIRectEdgeAll; try setting this to UIRectEdgeNone. Further explanation is available in Apple's iOS 7 transition guide.

Upvotes: 0

logixologist
logixologist

Reputation: 3834

I have found that when using the UINavigationBar in iOS7, the translucency setting will cause the navigated view to start off at 0,0 instead of factoring for it by using 64,0. If you change

Translucent = NO;

Your UINavigation bar wont cover up your new view. I had the same issue: Here

Good luck!

Upvotes: 2

Related Questions