我是 iOS 和 Objective C 编程世界的新手。我正在尝试创建一个将扫描条形码然后使用该数据访问网站的应用程序。
现在,唯一的问题是当我使用 webview 加载网站时,我不知道如何返回到 mainview/rootview。因为,我已经把它做成了一个基于 View 的应用程序,我不知道如何实现导航 Controller 或者只是一个后退按钮就可以了。
我用过这个 SDK:http://zbar.sourceforge.net/iphone/sdkdoc/
编码:
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
// ADD: get the decode results
id<NSFastEnumeration> results =
[info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
// EXAMPLE: just grab the first barcode
break;
// EXAMPLE: do something useful with the barcode data
resultText.text = symbol.data;
CGRect webFrame = CGRectMake(0.0, 0.0, 320.0, 460.0);
UIWebView *webView= [[UIWebView alloc] initWithFrame:webFrame];
[webView setBackgroundColor:[UIColor whiteColor]];
NSString *urlAddress= @"http://www.flipkart.com/search/a/books?query=";
urlAddress =[urlAddress stringByAppendingString:resultText.text];
NSURL *url= [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj= [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[self.view addSubview:webView];
// [webView release];
/*
// ADD: dismiss the controller (NB dismiss from the *reader*!)
[reader dismissModalViewControllerAnimated: YES];
}
如何在 webview 中添加后退按钮以便返回主视图?
最佳答案
这里有教程如何使用 UIWebView 实现工具栏:
http://iosdeveloperzone.com/2011/05/21/tutorial-building-a-web-browser-with-uiwebview-part-1/
关于iphone - 如何在 iOS 中从 webview 返回到 rootview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9858947/