first let me start by saying I'm pretty new to iPhone, so I apologise for my ignorance.
I've got a UITableView that I want to add new items to. When the add button is pressed, I want a modal screen to slide up where the user types in the text for the new item.
I've been reading from Apple's Table View Programming Guide for iPhone, and they have an example that supposedly does what I want:
- (void)addItem:sender {
// To add an item, display a modal view with a text field.
if (itemInputController == nil) {
itemInputController = [[ItemInputController alloc] init];
}
// Use a navigation controller to provide a customizable navigation bar with Cancel and Done buttons.
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:itemInputController];
[[self navigationController] presentModalViewController:navigationController animated:YES];
[navigationController release];
}
However they don't explain anywhere what itemInputController is. As far as I can determine it is supposed to give me a modal view with a single text field, and a navigation bar with Cancel and Save in it. Am I supposed to create this view myself in Interface Builder? Or is it a standard thing I need to import somehow? Can anyone help me decipher this, or alternatively show me another way to get this working?
ItemInputController will be a derivitave of UIViewController that you need to add to your project.
You'll need to create a new UIViewController subclass, then build the interface in IB - see here for a discussion on building UIViewControllers.
Related
My question is quite simple but no way to find a simple exemple on internet.
I have a main view controller with buttons and i'd like to display an UIView created with IB when i click on a button, so for exemple:
-ViewController (.h/.m/.xib) is my main interface with a menu button
-MenuView (.h/.m/.xib) is my view that i would like to be displayed as a pop up window over my uiviewcontroller.
So how is it possible to control my MenuView from my viewController ? Is it possible to create it with IB or is it better to make it programmatically? Thank you very much for your help!
I don't know for a way to do this only with interface builder, but the IB can help you. I will do it creating another view controller which contains the view you want to be shown. On your already existing view controller you can create a method i.e:
- (void) show: (id) sender {
UIViewController *theNewController = [TheNewController alloc] initWithNibName: #"TheNewController" bundle:[NSBundle mainBundle]];
[self presentViewController:theNewController animated:YES completion:nil];
}
and link this method, using the IB, to the button actions.(right click on the button in IB, choose the event i.e Touch Down, drag'n drop to the File's Owner). But I recommend you also seeing view controller's apple documentation: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html
I would like to combine UITableView and UINaviationController in an app but as a newbie most apps I've seen just send you straight to the results view (UITableView). But, I guess a "normal" search application does not assume you have the results on the first screen. There should be a search form on first screen with input fields and a button that triggers the search process and show some results and navigation.
So, I'm just trying to replicate this normal behaviour in my app. I've already made the search form (no navigation shown on it, of course) and a seperated View called "ListingViewController" with its related View and containing a UITableView and where I think I should add the Navigation...The next idea will be to make a DetailViewController and possibly and ListingMapController to show the listing in a GoogleMap.
So, where I'm stuck at is how to add this Navigation Controller ?
Some suggested me to add it in the SearchViewController delegate...
But I don't want a navigation on search form of course...
Some suggested me to open the Navigation controller modally...
But, I"m also planning at adding a Tab Bar to allow user to see other informations (like About,etc...) and with a modal Nav controller I don't know if they will still see the bottom Tabbar...
Any suggestions? What do you think is of best practices especially to avoid my app of being rejected by Apple?
Thx in advance for reading and helping!
Stephane
You could init the navigationController with your View Controller as the root view Controller. Then hide the navigationBar (if you need to). You would then add the navigationController.view as the subview. This will basically look like the original view controller. Then you can pushViewController: animated: to push the results view Controller.
So, for example in your AppDelegate (or in the proper view controller):
Create a property and ivar for a UINavigationController and hook up its outlets in interface builder. Then set your search controller as the root view controller for the nav bar, and add it as a subview.
MySearchViewController* searchController = [[MySearchViewController alloc] init];
self.myNavigationController = [[UINavigationController alloc] initWithRootController:searchController];
[searchController release];
self.myNavigationController.navigationBarHidden = YES;
[self.window addSubview:self.myNavigationController.view];
[self.window makeKeyAndVisible];
Then of course in your searchController, you would simply say:
ResultsViewController* myResultsViewController = [[MyResultsViewController alloc] init];
//You may want to create another init method and pass in some arguments like an array:
// [[MyResultsViewController alloc] initWithResults:results];
then push the viewController
//This is in your search controller class
[self.navigationController pushViewController:myResultsViewController Animated:YES];
[myResultsViewController release];
from the results viewController, to get back you pop the view controller off of the navigationController view controller's stack.
//In results view controller perhaps in some IBAction for a back button:
-(IBAction)backButtonPressed:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
I am designing an iPhone App wherein I would like there to be a main screen. I then want users to be able to hit an info button in the bottom right of this screen and enter an entirely different interface that will handle options and various forms of data display.
After some research on View Controllers in Apple's documentation, I have determined that I definitely want to use a modal view when the info button is pressed. My problem, though, is that the interface that fits best is a UITabBarController. I'd like to have a tab in my UITabBarController that represents the main screen and, when touched, will tell the main screen to dismiss the UITabBarController.
I have seen quite a few examples on the web where people add custom view controllers with buttons that trigger the modal view dismissal to tabs on the UITabBarController, but I would like to entirely avoid displaying an extra view. As soon as the user touches the main screen tab, I'd like the modal view to dismiss. I have already experimented with approaches that placed the main screen in the UITabBarController, and was not satisfied, so I'm hoping somebody out there is familiar with the rare modal UITabBarController design and can offer me some guidance.
Is this at all possible? If not, how can I accomplish the same interface flow in a different way?
I haven't tried this yet, but is there a way I could set the UITabBarController up with an empty UIViewController to represent the main screen and call on a UITabBarControllerDelegate to send the dismiss message to the main screen before the empty view appears?
Ok, I figured this out. I admit this is probably not the most orthodox UI design, but I think it does make intuitive sense... somebody should probably link me to the Apple UI guideline that this violates, though.
The following code will allow a user to press an info button that will animate the presentation of a modal UITabBarController. In this example, the UITabBarController has only one tab and the tab bar has not been set up with icons or titles. Once in the modal view, the user can click the first tab in the bar and the modal view will be dismissed. (This logically means that you'll want to tell the UITabBarController to start at an index other than the first.)
- (IBAction)infoButtonPressed
{
UIViewController *mainScreen = [[UIViewController alloc] init];
NSArray *viewControllers = [[NSArray alloc] initWithObjects:mainScreen, nil];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = viewControllers;
//This means that "self" needs to implement the UITabBarControllerDelegate protocol
tabBarController.delegate = self;
[self presentModalViewController:tabBarController animated:YES];
[mainScreen release];
[viewControllers release];
[tabBarController release];
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if (viewController == [tabBarController.viewControllers objectAtIndex:0]) {
[self dismissModalViewControllerAnimated:YES];
}
}
I am now, however, getting a warning about two-stage rotation animation:
Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations.
Using two-stage rotation animation is not supported when rotating more than one view controller or view controllers not the window delegate
Preliminary research said that it was because I was using a UIImageViewController to display a background on my mainScreen view, but I have since changed that to UIColor initWithPatternImage. Anybody know how to get rid of the warning-- or if it even matters to ignore it?
Sounds like a confusing (or at least unusual) user experience. Tabs are expected to be the apps main navigation level.
You should consider showing the sections in a segmented button or in a vertical list with back navigation (e.g. The preferences app)
This is the situation:
I have a tab bar with 2 tabs. Tab01 and Tab02.
In Tab01 I have a button which pushes repVC:
repVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:repVC animated:YES];
[(UIViewController *)[tabController.viewControllers objectAtIndex:0] setView:repVC.view];
[repVC release];
Inside repVC I have another button which pushes an MFMailComposerViewController:
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
[self presentModalViewController:mail animated:YES];
[mail release];
The problem is: when mailView is shown(in Tab01) and I click Tab02, then back to Tab01, the mailView is hidden and even if I click the email button again, the view won't be presented.
So what I have is: Tab01.view -> repVC.view -> mail.view
For repVC, I use this line when I push the view so that even if I go switch tabs, that view will still be activated:
[(UIViewController *)[tabController.viewControllers objectAtIndex:0] setView:repVC.view];
But I can't do the same for mail because tabController is declared in another class which I cannot import. So I can't access the tabController and set the view for Tab01.
Hope the edit helped the understanding.
Hmm,
I still would suggest to use a Navigationcontroller. Would make things way easier, is conform to apple guidelines and suggestions and is pretty fast implemented. (Just create a Navigationcontroller, put the View of Tab1 as main view and hand it over to the TabbarController. Then for the mailView use [self.navigationController pushViewController:mail animated:YES]; Then the navcontroller "saves" the present view for you when u switch tabs)
But if for some Reason you have to use a modalViewcontroller you could either just deactivate the tabbar while the ModalView is shown or try to implement a switch or a simple if...else case in your ViewWillAppear where u check what screen to load.
Then Clean out the Window and load the right screen.
Hope you get the idea of what I mean, sometimes my way of writing seems to confuse people. ^^
A little more information would be great.
How did u set up your TabbarController?
How do u push the new view? Within a UINavigationController? If not, then do it with a navController, he should save the actual state of view and your problem should be solved.
If u already use a navController please post your ViewDidLoad and ViewWillAppear of the Viewcontroller of Tab 1
As #Amandir points out you could probably solve your problems by using a UINavigationController. I get a feeling that you are trying to abuse the modal view controller concept a bit and that's why it doesn't work as you expect. When you use presentModalViewController:animated: the intention should be that you are displaying a view that is modal, i.e. the user must interact and dismiss the modal view before she can continue.
What the paragraph above means that when you present a modal view controller it shouldn't be possible to use the tab bar. Since you are using the word push I'm guessing that you would like change the view of Tab01 while still being able to use the functionality of the tab bar. The problem is that there isn't any built-in method of pushing view controllers besides UINavigationController. persentModalViewController:animated: should only be used in case where you want a modal view, which on the iPhone means a full screen view.
The easiest way would probably be to use an UINavigationController and hide the navigation bar. Then you would get the functionality I think you are after. The other option is to manually add and remove sub views.
[self.view addSubview:repVC.view];
and
[repVC.view removeFromSuperview];
[self.view addSubview:mail.view];
You can use block animations if you want some fancy transitions.
I have a view based app that works well. (In other words, I'm not going to start over with a Navigation-Based App template.)
It's an immersive app of sorts and I'm trying to add a Table View that loads in a new view when a button is pressed.
The loading the nib part works, but I can't seem to be able to add a navigation controller to the new view. I want to see a navigation bar on top with a done button and an edit button. Also, I want to the Table View entries to be empty.
I added a new file like so:
File-> New File -> UINavigationController subclass. I checked the UITableViewController Subclass and With XIB for user interface.
All I see when the view is pulled up is a blank Table View. I am able to customize things in the view controller.
What can I do to make the table show a navigation bar and be editable? I need some direction here please.
EDIT: I'm working with the latest Public SDK. (XCode 3.2.2)
The navigation bar usually comes with a navigation controller, not with the table view controller.
You can add the navigation bar manually, but that will require altering the table view, to change it to just a regular view with a table view inside of it, and changing your table view controller to be a regular view controller that manually handles the table view stuff.
The simpler alternative is to wrap your table view controller inside of a navigation controller before you display it. Something like:
MyTableViewController *myViewController = [[MyTableViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myViewController];
[myViewController release];
//Now display navigationController instead of myViewController, using something like:
[self presentModalViewController:navigationController animated:YES];