I have one UIViewController (DownloadManager) which downloads a webpage with UIWebView and display the downloaded content (say a pdf file). I want to use it as reusable component.
I am having another UIViewController pointing to a screen which contains 4 buttons each button should download and display one pdf file from webpage. I want to display the downloaded pdf as a embedded subview to the current screen. Basically don’t want navigation.
Here I tried to use DownloadManager as subview and display pdf as subview. Its working fine.
-
I read as Per screen one View Controller. But still can I use this approach ?
-
I have to send a email feedback from this screen. As soon as I present the MFMailComposeViewController the previous download manager subview disappears Technically what is happening here?
Please find the code snippet below:
//************************************************
@implement MyViewController
- (void) initWebView
{
downloadMgr = [[DownLoadViewController alloc] initWithNibName:@"DownLoadViewController" bundle:nil];
downloadMgr.view.frame = CGRectMake(140, 20, 300, 200);
downloadMgr.WebView.frame = CGRectMake(140, 20, 300, 200);
downloadMgr.view.backgroundColor = [UIColor whiteColor];
downloadMgr.WebView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:downloadMgr.view];
[self.view addSubview:downloadMgr.WebView];
}
----
----
- (IBAction)onHomeClick:(UIButton *)sender
{
switch (sender.tag)
{
case 101:
{
[self stopWebViewResources];
if (!downloadMgr) {
[self initWebView];
}
downloadMgr.NavigationURL = [[NSURL alloc] initWithString:@"https://xxx.yyyyyy.com/sites/pex/iPadFiles/abc.pdf"];
downloadMgr.title = @"ABC";
[downloadMgr LoadURL];
}
break;
case 120:
{
//Send feedback via email
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
----
----
mail.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentModalViewController:mail animated:YES];
}
}
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
@end
//*****************************************************************
@interface DownLoadViewController : UIViewController <MyWebViewDelegate>{
NSURL* NavigationURL;
IBOutlet myWebView* WebView;
IBOutlet UIActivityIndicatorView* ProgressView;
NSString* DownloadedFileName;
}
It is much more robust to separate the download functionality and the display into two different classes.
Ideally, you should have a class like “Downloader” or “Download Manager” which is a subclass of
NSObject. This class should do the download and notify its delegate when it is done. Then you can have as manyUIViewControllers as you like that take advantage of your Downloader class.