总而言之,我的应用程序中有一个浏览器,我希望它只启动 5 个网站,别无其他。有没有一种方法可以让我的浏览器通过设置自定义字符串来启动 5 个网站,比如 if {user types this string in} go to that then else {do not load}
这是我的 URL 部分的代码
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// go to 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];
}
对不起,如果它不是太详细,或者如果我遗漏了什么,我会说我是这个初学者。
这是我的附加代码
- (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 the loading icon disappear
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}