to sum up, have browser in app, , want launch 5 websites, nothing else. there way can make browser launch 5 websites setting customs strings, if {user types string in} go , else {do not load}
here code have url part
- (void)viewdidload { [super viewdidload]; // additional setup after loading view nib. // go google.com nsurl *urlrequest = [nsurl urlwithstring:@"http://www.google.com"]; nsurlrequest *request = [nsurlrequest requestwithurl:urlrequest]; // set text bar urlbar.text = [urlrequest absolutestring]; // load request [webview loadrequest:request]; // show loading icon [[uiapplication sharedapplication] setnetworkactivityindicatorvisible:yes]; }
and sorry if not in detail, or if missing something, beginner this.
here additional code had
- (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil: (uinavigationcontroller *)navigationcontroller: (controller *)transmission { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization self.controller = navigationcontroller; self.libtransmission = transmission; } return self; } - (ibaction)go:(id)sender { // create url request nsurl *urlrequest = [nsurl urlwithstring:urlbar.text]; nsurlrequest *request = [nsurlrequest requestwithurl:urlrequest]; // load request [webview loadrequest:request]; // make network icon visible [[uiapplication sharedapplication] setnetworkactivityindicatorvisible:yes]; } - (void)webviewdidfinishload:(uiwebview *)webview { // update urlbar urlbar.text = webview.request.url.absolutestring; // make loading icon disappear [[uiapplication sharedapplication] setnetworkactivityindicatorvisible:no]; } - (bool)textfieldshouldreturn:(uitextfield *)textfield { [textfield resignfirstresponder]; return yes; } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. }
put sites can accessed array, , go through array see if string typed in in array, this
nsarray *sites = @[@"http://test.com", @"http://test1.com", @"http://test2.com", @"http://test3.com", @"http://test4.com"]; nsstring *urltoopen = urltextfield.text; (nsstring *str in sites){ if ([urltoopen isequaltostring:str]){ nsurl *urlrequest = [nsurl urlwithstring:urltoopen]; nsurlrequest *request = [nsurlrequest requestwithurl:urlrequest]; urlbar.text = [urlrequest absolutestring]; [webview loadrequest:request]; } else{ //url user entered not 1 of 5 urls } }
Comments
Post a Comment