Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3662330
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:24:16+00:00 2026-05-19T01:24:16+00:00

In my iOS application, I want to provide a settings-view. presentModalViewController works very well:

  • 0

In my iOS application, I want to provide a settings-view. “presentModalViewController” works very well:

ViewSettings *controller = [[ViewSettings alloc] initWithNibName:@"ViewSettings" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
[self.navigationController presentModalViewController:navController animated:YES];      
[controller release];
[navController release];

Unfortunately, I have to change my running code and create the ViewSettings including the UINavigationController in Interface Builder. Why? Long story, I’ll explain it in the end of this thread…

I try to drag and drop an UINavigationController in my ViewSettings and create an IBOutlet to access it in my class. I give this controller to “presentModalViewController” but the application crashed…

What I’m doing wrong?


[EDIT]

Error Message: GDB: Program received signal: “SIGABRT”.
The error happens in the last line of this code:

ViewSettings *viewSettings = [[ViewSettings alloc] initWithNibName:@"ViewSettings" bundle:nil];
UINavigationController *navController = viewSettings.navigationController;
UINavigationBar *navBar = navController.navigationBar;
OwnNavigationBar *ownNavBar = (OwnNavigationBar *)navBar;
[ownNavBar drawHeaderImage:YES];
[self.navigationController presentModalViewController:navController animated:YES];

Detailed Error: Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘Application tried to present a nil modal view controller on target .’

[/EDIT]


[EDIT2]
Thanks for your help!
Yes, navigationController is nil…
I think I add the UINavigationController in a wrong way… I put it in this window, because it was not possible to put it directly in my view:
alt text
How do I add the UINavigationController correct?
[/EDIT2]


PS: Why do I have to use IB? (you can skip this…)

I need an background image in my UINavigationBar. My first try was:

UIImage *image = [UIImage imageNamed: @"header.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[self.navigationController.navigationBar addSubview:imageView];
[self.navigationController.navigationBar sendSubviewToBack:imageView];

But in some issues, the title oder a UIBarButton is not visible! I tried a lot, e.g. sets the “tag” of the view and sendSubviewToBack in each view, but no success. This is a very annoying bug!

My second try was to create a category and overwrite the drawRect-method:

@implementation UINavigationBar(MyNavigationBar)
- (void)drawRect:(CGRect)rect {
    UIImage *image = [UIImage imageNamed: @"header.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end

But now, all of my UINavigationBars have an background image and I can’t deactivate it. The problem is, that “ViewSettings” needs the background image, but the following pushed views do not.

Unfortunately, it isn’t possible to set a property in a category or call [super drawRect:rect] to avoid painting the image.

My last try is to write an own UINavigationBar

@interface OwnNavigationBar : UINavigationBar {
    BOOL _drawHeaderImage;
}

Now I can control the drawRect-method!! GREAT!!

- (void)drawRect:(CGRect)rect {
    if (_drawHeaderImage) {
        UIImage *image = [UIImage imageNamed: @"header.png"];
        [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    }
    else {
        [super drawRect: rect];
    }
}

But I celebrate to early… 🙁
It isn’t possible to set an own UINavigationBar in the UINavigationController!!!
“navigationBar” in UINavigationController is a read-only property!
AAAAHHHHHHHHHH!

I have one last chance: in Interface Builder it is possible to give an UINavigationController an own UINavigationBar!!
YES! I GOT IT!! 🙂

I configured it in my MainWindow_iPhone.xib and it works great!
Now, I have to implement this for my ViewSettings, because this (modal) view needs a new UINavigationController.

PS: Maybe, someone can send this thread to Apple, this all are very annoying circumstances and bugs 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:24:17+00:00Added an answer on May 19, 2026 at 1:24 am

    When you init a view controller from a nib, it does not actually load the nib right away, so viewSettings.navigationController is still nil. The first time you reference the view property, the nib will be loaded.

    Update

    You could load the nib yourself and grab the navigation controller, like so:

    UINavigationController *navController = [[[NSBundle mainBundle] loadNibNamed:@"ViewSettings" owner:self options:nil] objectAtIndex:1];
    

    I used object at index 1 because in your screenshot there’s a tableview which I think will be index 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a custom alert view within my iOS application. For example,
I am working on a simple Table View iOS application, and I want to
I want to put a feedback form in a view in my IOS application.
I want to create UI in my application same as, iOS uses in Settings
I want to create an iOS application which consists of Tamil language. I see
I'm developing an iOS 4.0 application. I want to add a custom UIView over
I'm building a PhoneGap 1.5 (Cordova) application for iOS and want to use the
I want to create a simple desktop admin application for an IOS app that
Just to be sure, I want to know if an application targeted for IOS
I want to build an iOS application that recognizes patterns in a cup of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.