我有一个带有三个标签的Tabbar iOS应用程序。我将每个标签设置为UIWebView。我希望每个Web视图都显示不同的PDF。如何通过代码将每个webview分配给相应的pdf?
答案 0 :(得分: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
}