0

小さな問題があります。基本的にUIWebView、ナビゲーション バーの下に があるので、コンテンツを表示するには下にスクロールする必要があり、最後に上にスクロールします。UIWebViewをナビゲーション バーのすぐ下に表示するにはどうすればよいですか?

#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

main.mm コード:

int main(int argc, char **argv) {
        NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
        int ret = UIApplicationMain(argc, argv, @"comvlad1kwebApplication", @"comvlad1kwebApplication");
        [p drain];
        return ret;
}

// vim:ft=objc

私は Theos を使用しているため、Xcode を持っていないため、手動で行う必要があります。ありがとうございました。

編集: スクリーンショットへのリンクは次のとおりです: http://i.imgur.com/aQ4yuyp.png

4

2 に答える 2

2

主な問題は、UINavigationBar手動で作成していることです。これUINavigationControllerは、他のView Controllerのスタックとそれらの間のナビゲーションを管理するView Controllerです。アプリケーション デリゲートには、おそらく次のようなコードがあります。

// Assuming that your UIApplication Delegate has a _viewController ivar which is properly memory-managed.
- (void)applicationDidFinishLaunching:(UIApplication *)application {
    _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    _viewController = [[RootViewController alloc] init];
    [_window addSubview:_viewController.view];
    [_window makeKeyAndVisible];
}

このコード スニペットは、 のインスタンスを作成し、RootViewControllerそれをアプリケーションのメイン ビュー コントローラーに設定します。代わりに、次のように a を a のRootViewController中に入れます。UINavigationController

// Assuming that your UIApplication Delegate has a _viewController ivar which is properly memory-managed.
- (void)applicationDidFinishLaunching:(UIApplication *)application {
    _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    _viewController = [[RootViewController alloc] init];
    UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:_viewController] autorelease];
    [_window addSubview:navController.view];
    [_window makeKeyAndVisible];
}

UINavigationControllerサブクラスを作成したら、不要になったため、UINavigationBarからを削除する必要があります。RootViewController

于 2013-09-16T19:36:10.273 に答える