Navigation Bar is OVER the UIViewWeb?

Discussion in 'iOS Programming' started by Vlad1k, Sep 16, 2013.

  1. Vlad1k macrumors newbie

    Joined:
    Sep 16, 2013
    Location:
    Saint Louis, US.
    #1
    Hey guys!
    I am not 100% sure if this is the correct section, but I am creating an app using Theos (without Xcode), and I have an issue. My navigation bar is over the UIViewWeb, so I have to scroll down to view the top part of the UIViewWeb.

    Here is a screenshot:
    [​IMG]

    Here is my code:
    RootViewController.mm
    Code:
    #import "RootViewController.h"
    @implementation RootViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        webview=[[UIWebView alloc]initWithFrame:self.view.bounds];
        NSString *url=@"http://localhost/";
        NSURL *nsurl=[NSURL URLWithString:url];
        NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
        [webview loadRequest:nsrequest];
        [self.view addSubview:webview];
    
        navBar = [[UINavigationBar alloc] init];
        navBar.frame = CGRectMake(0, 0, self.view.frame.size.width, 44);
        UINavigationItem*navItem = [[[UINavigationItem alloc] initWithTitle:@"iPaint"] autorelease];
        UIBarButtonItem*leftButton = [[[UIBarButtonItem alloc] initWithTitle:@"Left" style:UIBarButtonItemStylePlain target:self action:@selector(rightButtonPressed)] autorelease];
        navItem.leftBarButtonItem = leftButton;
    UIBarButtonItem*rightButton = [[[UIBarButtonItem alloc] initWithTitle:@"Right" style:UIBarButtonItemStylePlain target:self action:@selector(rightButtonPressed)] autorelease];
        navItem.rightBarButtonItem = rightButton;
    navBar.barStyle = UIBarStyleDefault;
        navBar.items = [NSArray arrayWithObject:navItem];
        [self.view addSubview:navBar];
    }
    
    -(void)leftButtonPressed{
    //Code Here
    }
    
    -(void)rightButtonPressed{
    //Code Here
    }
    @end
    RootViewController.h
    Code:
    @interface RootViewController: UIViewController {
    UIWebView *webview;
    UINavigationBar*navBar;
    @end
    }
    main.m
    Code:
    int main(int argc, char **argv) {
            NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
            int ret = UIApplicationMain(argc, argv, @"comvlad1kwebApplication", @"comvlad1kwebApplication");
            [p drain];
            return ret;
    }
    Thanks in advanced, I really appreciate it. I am really new to this new Obective-C stuff and it's really complicated right now. If this is in the wrong section, @moderators, please move it to a right one. Thank you. :D
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    Just curious: why are you using Theos instead of Xcode? If you were using Xcode you could use its interface builder tool which would get rid of most of the code you've written so far, and I suspect you wouldn't end up with the bug you're having.
     
  3. Vlad1k thread starter macrumors newbie

    Joined:
    Sep 16, 2013
    Location:
    Saint Louis, US.
    #3
    I don't have permissions to use Xcode on my school Mac Air, and I don't have a personal personal Mac, so I can't compile anything. So the only thing that's left is Theos.
     
  4. Sonnestah macrumors regular

    Joined:
    Mar 2, 2013
    #4
    Can't you ask for permission? :p

    Your problem is right here:

    Code:
    webview=[[UIWebView alloc]initWithFrame:self.view.bounds];
    You're initialising it with the total area of your view and forgot the navigation bar takes 44 from your total height. Instead of self.view.bounds, use CGRectMake()
     
  5. Vlad1k thread starter macrumors newbie

    Joined:
    Sep 16, 2013
    Location:
    Saint Louis, US.
    #5
    Could you please provide an example?
     
  6. Sonnestah macrumors regular

    Joined:
    Mar 2, 2013
    #6
    You did use it to create your navigation bar...... Or did you copy-paste your code? :eek:

    Anyway, this should work:

    Code:
    webview=[[UIWebView alloc]initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, self.view.frame.size.height - 44)];
     
  7. Vlad1k thread starter macrumors newbie

    Joined:
    Sep 16, 2013
    Location:
    Saint Louis, US.
    #7
    I was using a tutorial, and I am not sure if your solution works, but I was just in the IRC and I was able to fix the issue.
     

Share This Page