【发布时间】:2010-03-30 19:33:42
【问题描述】:
我是这些论坛的新手,所以我为我的菜鸟道歉。我尽我所能进行了彻底的搜索,但我找不到其他人遇到这个问题,如果其他地方已经涵盖了这个问题,请采纳。
我为我的问题创建了一个非常简单的示例。我确定我遗漏了一些东西,但我终生无法弄清楚是什么。
我正在创建一个 UIWebView 并将其添加到从 UIViewController 继承的自定义视图控制器中。当应用程序在 iPad 模拟器中加载时,uiwebview 会加载所需的页面,但 UIWebView 完全没有响应。 webview 不会平移或滚动,并且无法单击任何页内链接。但是,如果你突然改变 webview 的方向,一切都会正常。
提前感谢您的帮助!!
AppDelegate 标头
#import <UIKit/UIKit.h>
#import "EditorViewController.h"
@interface FixEditorTestAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
EditorViewController *editorView;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) EditorViewController *editorView;
@end
AppDelegate 实现
#import "FixEditorTestAppDelegate.h"
#import "EditorViewController.h"
@implementation FixEditorTestAppDelegate
@synthesize window;
@synthesize editorView;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(@"application is loading");
editorView = [[EditorViewController alloc] init];
[window addSubview:[editorView view]];
[window makeKeyAndVisible];
return YES;
}
- (void)dealloc {
[window release];
[editorView release];
[super dealloc];
}
@end
查看控制器标题
#import <UIKit/UIKit.h>
@interface EditorViewController : UIViewController <UIWebViewDelegate> {
UIWebView *webView;
}
@property (nonatomic, retain) UIWebView *webView;
@end
查看控制器实现
#import "EditorViewController.h"
@implementation EditorViewController
@synthesize webView;
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
NSLog(@"loadView called");
UIView *curView = [[UIView alloc] init];
webView = [[UIWebView alloc] init];
webView.frame = CGRectMake(20, 40, 728, 964);
webView.delegate = self;
webView.backgroundColor = [UIColor redColor];
[curView addSubview: webView];
self.view = curView;
[curView release];
}
//Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"viewDidLoad called");
NSURL *url = [[NSURL alloc] initWithString:@"http://www.nytimes.com"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
[webView loadRequest:request];
[url autorelease];
[request release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
return YES;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
webView.delegate = nil;
[webView release];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
【问题讨论】:
标签: objective-c ipad uiwebview