1
응용 프로그램에있는 모든보기에 UIWebView를 추가하고 싶습니다. 웹보기가로드되고 표시되지 않습니다. 어떤 사람도 저를 도울 수 있습니까?모든보기에 대해 공유 된 UIWebView
나는 공유 웹보기 클래스를 만들었습니다.
//.h Implementation
@interface WebViewAdds : UIWebView {
}
+ (WebViewAdds *) sharedWebView ;
@end
WebViewAdds *g_sharedWebView ;
@implementation WebViewAdds
+(WebViewAdds *) sharedWebView
{
if (g_sharedWebView == nil) {
g_sharedWebView = [[WebViewAdds alloc] initWithFrame:CGRectMake(0, 400, 320, 60)];
[g_sharedWebView setDelegate:self];
NSString *urlAddress = @"http://www.google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[g_sharedWebView loadRequest:requestObj];
}
return g_sharedWebView;
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code.
}
return self;
}
- (void)dealloc {
[super dealloc];
}
@end
그리고 모든 뷰 컨트롤러에서
, 나는 내가 보는 두 가지 문제가 있습니다-(UIWebView *) testWebView {
return [WebViewAdds sharedWebView] ;
}
-(void) viewDidLoad {
[super viewDidLoad];
[self.view addSubview:self.testWebView];
}
[g_sharedWebView setDelegate : self]; 대리자 메서드를 구현하지 않으면 불필요 해 보입니다. – Seyther