我有一个带有三个选项卡的 Tabbar iOS 应用程序。我将每个选项卡都设置为 UIWebView。我希望每个 Web 视图显示不同的 PDF。如何通过代码将每个 webview 分配给其相应的 pdf?
问问题
61 次
1 回答
0
它在您的 中看起来像这样AppDelegate
:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
WebViewController *webViewController1 = [[WebViewController alloc] initWithPDFAtURL:@"urlToPDF1"];
WebViewController *webViewController2 = [[WebViewController alloc] initWithPDFAtURL:@"urlToPDF2"];
WebViewController *webViewController3 = [[WebViewController alloc] initWithPDFAtURL:@"urlToPDF3"];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:[NSArray arrayWithObjects:webViewController1, webViewController2, webViewController3, nil]];
self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
您将需要一个视图控制器来保存UIWebView
, 并且可能类似于:
// WebViewController.h
@interface WebViewController : UIViewController
@end
// WebViewController.m
@interface WebViewController ()
@property (nonatomic, strong) NSURL *_pdfURL;
@end
@implementation WebViewController
@synthesize _pdfURL;
- (id)initWithPDFAtURL:(NSURL *)url {
self = [super init];
if (self) {
_pdfURL = url;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Load the PDF into a UIWebView
}
于 2013-03-07T05:15:16.870 回答