how to open an in app browser like the mailcomposion popup - iphone

is it possible to open an in-app browser that loads a pdf and the takes you back to the nib just like the mailcomposition does with the in-app email? If so, can anyone please help.

You should be able to use a UIWebView controlled by a custom UIViewController, which you present using the presentModalViewController:animated: method in the view controller that wants to pop up the PDF.

1) Create a .xib and corresponding view controller (both named WebViewViewController here). This should include a UIWebView (to display the PDF) and a UIButton (to close the modal view & return to your original view).
2) Present your WebViewViewController as a modal view. This will "pop-over" your current view with the new view.
WebViewViewController *webViewVC = [[WebViewViewController alloc] initWithNibName:#"WebViewViewController" bundle:nil];
//I am showing it over a Navigation Controller, you may be using something different.
[self.navigationController presentModalViewController:webViewVC animated:YES];
[webViewVC release];
3) In your WebViewViewController, wire up an IBAction method to your "Close" button. In that method use this to dismiss the "pop-over" view.
//
[self dismissModalViewControllerAnimated:YES];
Let me know if you need help with loading the PDF into the UIWebView.

Related

Navigate from one view to another using UIButton

I have an application with 2 views . In the first one I have a button which when I clicked the user should go to the second view. I tried what is explained before here from Karoley , but it does not work . When I click the button nothing happened?
Here is the code of my action :
-(IBAction)gotoSecondPage:(id) sender{
NSLog(#"In gotoSecondPage");
LeoActionViewController *aSecondPageController =
[[LeoActionViewController alloc]
initWithNibName:#"LeoActionViewController"
bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:aSecondPageController animated:YES];
}
LeoActionViewCOntroller is a controler for a second view.
It just do not switch to a second view. I do not know why
I put code your problem this will help you. First of all, you declare method and open .xib file and then connect to that button with selected touchupinside connection.
In the .h file:
- (IBAction)gotoSecondPage:(id) sender;
In the .m file:
- (IBAction)gotoSecondPage:(id) sender
{
NSLog(#"In gotoSecondPage");
LeoActionViewController *aSecondPageController =
[[LeoActionViewController alloc]
initWithNibName:#"LeoActionViewController"
bundle:nil];
[self.navigationController pushViewController:aSecondPageController animated:YES];
[aSecondPageController release];
}
I'm not sure in what capacity you want to switch views.
What immediately comes to mind is that you want a Navigation Controller. This is an object that lets you put view controllers on a stack and push and pop them to show and hide them. It creates a navigation pathway through your app and is easy to use. It also facilitates the 'standard' navigation bar which is found in many iphone apps.
If you just want to change one view for another view you can do many things including hiding and showing different views using setHidden:(bool)hidden. Otherwise you can use addSubview:(UIView *)view and removeFromSuperview to add and remove views completely from the superview.

iPhone: How to show pop-up windows and dismiss them

In my Universal App I have a long UITableView with custom cells..and for some cells I may need to show some long pop-up explanaiton about that cell when for instance user clicks a "i" label on the cell. In iPad popover view seems excellent choice for this, but don't know how can I implement this on iPhone, what are the possibilities? Also I want to spend as less time as possible when making it work for iPad- popover view. I want to re-use some of the code or logic i use on iPhone
Things came up to my mind;
-Show explaination in alert shild, but the current look and feel of alert shield is ugly can I customize it however I like and show wherever I line on screen and if I can make it scrollable;
-Or maybe I can make a uitextview to show on top, but then how will I dismiss it, I will need some buttons there..which sounds tricky.
-UIActionsheet with a uitextview on it, is reasonable here?
Also I found this code in S.O but dont know how to use this in my case;
newView.frame = CGRectMake(60, 140, 200, 200);
[parentView addSubview:newView];
Have a look at http://iosdevelopertips.com/open-source/ios-open-source-popover-api-for-iphone-wepopover.html. It's a Popover component for iPhone. I think it works best in your case. You can Google "iphone popover" for more options.
We built an open source library for iPad-like popovers on iPhone allowing you to customise the look and feel of the popovers and place any view or controller inside it.
Watch the project on Github and download it at http://www.50pixels.com/blog/labs/open-library-fppopover-ipad-like-popovers-for-iphone/
On dismissing it, see the following instructions:
Know when a new popover is displayed
- (void)presentedNewPopoverController:(FPPopoverController *)newPopoverController
shouldDismissVisiblePopover:(FPPopoverController*)visiblePopoverController;
Use this delegate method to know when a new different popover is displayed. If you want to dismiss the old popover, and release it, send the dismiss message inside this method.
- (void)presentedNewPopoverController:(FPPopoverController *)newPopoverController
shouldDismissVisiblePopover:(FPPopoverController*)visiblePopoverController
{
[visiblePopoverController dismissPopoverAnimated:YES];
[visiblePopoverController autorelease];
}
Know when the popover is dismissed
- (void)popoverControllerDidDismissPopover:(FPPopoverController *)popoverController;
Use this delegate method to know when the popover is dismissed. This could happen when the user taps outside the popover or when a dismiss message is sent by other actions.
Typically if you used a UIPopover on the iPad you use present a Modal view controller on the iPhone.
So if you create a subclass of UIViewController (e.g. called MyViewController), with the necessary subviews such as a UILabel.
MyViewController *infoViewController = [[MyViewController alloc] init];
//pass data to the new view controller, e.g.
//[infoViewController setInfoText:...];
[self presentModalViewController:infoViewController animated:YES];
[infoViewController release];

How to closw webView?

I am designing a webView with a close button. When the application is launched, it opens the given url. When the button is touched, i want to close the webView.
I need some button event which closes the webView. Thank you for your answers.
UIWebView inherits from UIView. So the answer is: It depends!
If you're using a UINavigationController and used
[[self navigationController] pushViewController:newUIWebController];
you can close your UIView by using
[self.navigationController popViewControllerAnimated:YES];
If you're using some other method to display your view (like addSubView) you can utilize the corresponding method like removeFromSuperview.

Navigation based application with an add button

I created a new Navigation Based Application project.Then in MainWindow.xib I added a button to the navigationbar. I would like to push a new View onto the screen where I can enter information, which will be added as an object to the array of the UITableView.
But I don't know where to write the IBAction to link the button to (Appdelegate or the RootViewController)? Because as you see in the screenshot, it resides in MainWindow.xib because the RootViewController is merely a Table and doesn't contain the navigation. But in the document view of MainWindow.xib it is located under the RootViewController.
Do I have to create a new View Controller inside the XIB as well and create an IBOutlet for it?
I tried putting the code inside my AppDelegate and reference the button to the delegate but it doesn't work.
Please help. Thanks in advance.
See the screenshot here: http://i56.tinypic.com/5djbcm.png
When you ask yourself a question "where does this action belong" it's most probably a controller because controllers handle event flows in your app. Next question - "What controller is in charge when this action happens? What controller is most interested in this action?". Answer in your case is root table controller (RootViewController instance). Create an IBAction method in it which will push form controller (one you use to enter information) to navigation controller.
// somewhere in RootViewController.m
- (IBAction)addNewEntry {
NewEntryFormController *c = [[[NewEntryFormController alloc] init] autorelease];
// ...
[self.navigationController pushViewController:c animated:YES];
}

iPhone ModalViewController For Table View Open by Button?

App Description: I have a UIWebview and a Toolbar beneath it. A button on the toolbar should bring up a modal table view, but it does not.
The toolbar has four buttons:
Previous: Goes to previous site
Next: Goes to the next site (these two being different than the default goForward and goBack methods)
Menu: Display a modalViewController with a TableView of all the available sites (sites will be limited to an array of site links that the next and previous buttons cycle through)
Refresh: Refreshes current site
Application has four main classes/files
WebAppDelegate.h and .m
ListViewController.h and .m (which has the Table View in its xib and the code to fill the table in the .m/ be the modal view controller)
There is only one warning and no errors.
Warning: 'WebAppDelegate' may not repsond to '-presentModalViewController:animated:'
When I run the program, everything is fine until I click the Menu button. I receive this runtime error
[WebAppDelegate presentModalViewController:animated:]: unrecognized selector sent to instance
Below is the code for the Menu button, which is currently in WebAppDelegate.m
-(IBAction)menu:(id)sender {
ListViewController *aListView=[[ListViewController alloc] initWithNibName:#"ListViewController" bundle:[NSBundle mainBundle]];
[self setListController:aListView];
aListView.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
[self presentModalViewController:aListView animated:YES];
[aListView release];
}
Any ideas on what causes the application to crash and why the modal table view does not display?
The error message tells you exactly what your problem is - you're sending a selector to an object that doesn't respond to that selector.
[self presentModalViewController:aListView animated:YES];
self in this case in your instance of WebAppDelegate, which is probably a subclass of NSObject, not UIViewController. presentModalViewController:animated: is a method on UIViewController, so you need to send that message to whatever view controller is currently displayed (or perhaps a navigation controller) if you want to present another view controller modally.
Do not ignore compiler warnings - the one warning you have is likely telling you that...
'WebAppDelegate' may not respond to '-presentModalViewController:animated:'
...which, again, is exactly your problem.
[self.navigationController presentModalViewController:aListView animated:YES];