我在 iOS4 上的应用程序(ipad)有问题。键盘不起作用,在第一个视图(登录视图)之后不会显示在我的 web 视图上。
应用程序:
AppDelegate.h
@class RootViewController;
@interface StandardFacileAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
RootViewController *rootViewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet RootViewController *rootViewController;
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
rootViewController = [[RootViewController alloc] init];
window.rootViewController = rootViewController;
//[window addSubview:rootViewController.view];
[window makeKeyAndVisible];
return YES;
}
根视图控制器:
- (void)viewDidLoad {
[super viewDidLoad];
[self loadViewController];
[self.view addSubview:viewController.view];
}
- (void)loadViewController {
ViewController *viewControllertemp = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
self.viewController = viewControllertemp;
[viewControllertemp release];}
viewController 是我请求后的登录视图,我调用了更改视图的方法(我的 webview):
- (void)changeViewToIpadTheWebView:(UIViewController *)fromView{
UIViewController *currentView = (UIViewController*)fromView;
NSLog(@"currentView =>%@",currentView);
if(!ipadTheWebView)
[self loadipadTheWebView];
[currentView.view removeFromSuperview];
for (UIView *view in [self.view subviews]) {
[view removeFromSuperview];
}
[self.view addSubview:ipadTheWebView.view];
NSURL *url = [NSURL URLWithString:@"http://www.google.com/"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
[ipadTheWebView.webView loadRequest:requestURL];
我的 webview 没问题,但如果我想在 google 中搜索单词,当文本字段获得焦点时,键盘不会显示(视图滚动)。
有什么问题,这段代码适用于 iOS5 而不是 ios4?
谢谢你的帮助 ;)
编辑:谢谢马修,
RootViewController.h
#import <UIKit/UIKit.h>
@class ViewController;
@class IpadTheWebView;
@interface RootViewController : UIViewController {
ViewController *viewController;
IpadTheWebView *ipadTheWebView;
}
@property (nonatomic,retain) ViewController *viewController;
- (void)loadViewController;
- (void)changeViewToViewController:(UIViewController *)fromView;
@property (nonatomic,retain) IpadTheWebView *ipadTheWebView;
- (void)loadipadTheWebView;
- (void)changeViewToIpadTheWebView:(UIViewController *)fromView;
- (void)keyboardWillShow:(NSNotification *)notification;
- (void)keyboardWillHide:(NSNotification *)note;
@end