ios - Only black screen in my UIWebView -
i have 2 view controllers. in first 1 have button , when click need display web page in second view controller. when click button, see black screen.
here tabulkaviewcontroller.m code:
#import "tabulkaviewcontroller.h" #import "webviewcontroller.h" @interface tabulkaviewcontroller () @end @implementation tabulkaviewcontroller - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization } return self; } - (void)viewdidload { [super viewdidload]; // additional setup after loading view. _hbutton.layer.borderwidth = 1; _hbutton.layer.bordercolor = [[uicolor graycolor] cgcolor]; } - (ibaction)hbutton:(id)sender { nsurl *url = [nsurl urlwithstring:@"http://apple.com"]; webviewcontroller *webviewcontroller = [[webviewcontroller alloc] initwithurl:url andtitle:@"apple"]; [self presentviewcontroller:webviewcontroller animated:yes completion:nil]; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. }
here code of webviewcontroller.h:
#import <uikit/uikit.h> @interface webviewcontroller : uiviewcontroller <uiwebviewdelegate> { nsurl *theurl; nsstring *thetitle; iboutlet uiwebview *webview; iboutlet uinavigationitem *webtitle; } - (id)initwithurl:(nsurl *)url; - (id)initwithurl:(nsurl *)url andtitle:(nsstring *)string; - (ibaction) done:(id)sender; @end
and here code of webviewcontroller.m:
#import "webviewcontroller.h" @interface webviewcontroller () @end @implementation webviewcontroller - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization } return self; } - (void)viewdidload { [super viewdidload]; webtitle.title = thetitle; nsurlrequest *requestobject = [nsurlrequest requestwithurl:theurl]; [webview loadrequest:requestobject];} - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } - (id)initwithurl:(nsurl *)url andtitle:(nsstring *)string { if( self = [super init] ) { theurl = url; thetitle = string; } return self; } -(id)initwithurl:(nsurl *)url { return [self initwithurl:url andtitle:nil]; } - (ibaction) done:(id)sender { [self dismissviewcontrolleranimated:yes completion:nil]; } - (void)viewwilldisappear:(bool)animated { [super viewwilldisappear:animated]; webview.delegate = nil; [webview stoploading]; } -(void)webviewdidstartload:(uiwebview *)webview { [uiapplication sharedapplication].networkactivityindicatorvisible = yes; } -(void)webviewdidfinishload:(uiwebview *)webview { [uiapplication sharedapplication].networkactivityindicatorvisible = no; }
you need instantiate webview @ point. suggest change viewdidload this:
- (void)viewdidload { [super viewdidload]; webview = [[uiwebview alloc] init]; webtitle.title = thetitle; nsurlrequest *requestobject = [nsurlrequest requestwithurl:theurl]; [webview loadrequest:requestobject]; }
since webview null
at start of method, needs created before can load requests. declaring in header file not enough, thats why need webview = [[uiwebview alloc] init];
.
edit:
of course, put line ìnitwithurl:andtitle: method, other instantiations take place.
Comments
Post a Comment