I have created an application for iPhone interface which displays a UITableView as its rootviewcontroller. When we select any of its row, it opens the corresponding detailViewController, we select the value from there and it is displayed in the cells of UITableView in masterViewController. This application was running perfectly fine in iPhone simulator as desired.
Now I want to incorporate this application to an iPad application. For that purpose, I have created a UIPopOver and assigned the masterViewController to the popover. Now the problem is, UITableView is initially shown in the popover. But when we select any row, next view doesn't appear in popover as it appeared when application was running solely for iPhone. How should I make it work so that I can import the application with original functionality in UIPopOver?
I think you are pushing DetailViewController from your masterViewController.But your masterviewController should implement NavigationController, I mean while displaying masterViewController(your tableviewcontroller) in popover you should do as follows:
MasterViewController *theMasterViewController = [[MasterViewController alloc] init];
UINavigationController *navCont = [[UINavigationController alloc] initWithRootViewController:theMasterViewController];
[theMasterViewController release];
UIPopoverController *popOverController = [[UIPopoverController alloc] initWithContentViewController:navCont];
popOverController.popoverContentSize = CGSizeMake(400, 400);
[popOverController presentPopoverFromRect:btn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
and when user selects any row, then in didSelectRowAtIndexPath do as follows:
DetailViewController *detailViewController = [[DetailViewController alloc] init];
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
Hope this helps!
Related
My app is a ViewBased app. I added a subclass of type UITableView with its .xib
when i press a button i want to load the UITableView xib but it loads only the table with no Navigation bar and search bar i added.
Here's the code to load the view:
- (IBAction)changeView:(id)sender;
{
TableViewController *tableview =[[TableViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:tableview animated:YES];
}
This is what I want to load:
image 1 http://img571.imageshack.us/img571/3846/wantf.png
and this is what it loads:
image 2 http://img528.imageshack.us/img528/9928/loadu.png
How can I solve the issue and load the view with nav and search bar ?
Thanks in advance mates.
You need to wrap your view controller in a UINavigationController, like this:
UINavigationController: Simplest Example
So try this:
TableViewController *tableview =[[TableViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:tableview];
[self presentModalViewController:navController animated:YES];
When editing your xib file, I believe XCode gives you the option of showing/hiding your search bar.
I will use UINAvigationController in my app, but noticed that my rootview should be either a tableview or a uiview depending on content I received. as you know It comes with a tableview by default. how can I push my first view dynmacally here ?
U can do like this in application:didFinishLaunchingWith.... in app delegate.
For this, u need to create the application with window based application template.
DetailViewController *detailView = [[DetailViewController alloc] initWithNibnam..];
UINavigationController *uiNavController = [[UINavigationController alloc] initWithRootViewController:detailView];
self.window.rootViewController = uiNavController;
[detailView release];
[uiNavController release];
So before I've managed to work with TabBarViewControllers and create an application using them. However every time I do so the view acts as my main view. This time around I want my TabBarView to be my second view in my application
E.g
First window has a bunch of buttons, when I click one of these buttons I want the second view to show up. This view includes a TabBarViewController.
The farthest I've gotten is to have the button show a view but for some reason it won't show my TabBar view!
Here's the code for my button
- (IBAction)showEvents:(id)sender {
EventsViewController *controller = [[EventsViewController alloc] initWithNibName:#"EventsView" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
}
Any of you guys able to help?
Can't you just in the EventsViewController add the following code in viewDidLoad:
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = [NSArray arrayWithObjects: vc1, vc2, ..., nil];
Anyway, I found a solution and it was actually quite simple. After creating the Outlet for the TabBarController and linking it together with File's Owner all I had to do was add
self.view = tabViewController.view;
On the viewDidLoad method
In my app there is requirement that..I have 6 buttons in a nib,
when I press any button a new nib will be loaded into the window according to the button pressed. problem is after loading the new nib If I want to come back to the previous nib (which is having all the buttons) how to add navigation controller?
what I am doing now is while loading the new nib when I pressed the button
objNewViewController = [[NewViewController alloc] initWithNibName:#"NewViewController" bundle:nil];
[self.navigationController pushViewController:objNewViewController animated:YES];
but by this way im not able to load the nib, it's not performing any operation?
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[[NewViewController alloc] initWithNibName:#"NewViewController" bundle:nil]];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
And in NewViewController:
USe this to dismiss and get back to previous view.
[[self navigationController] dismissModalViewControllerAnimated:YES];
There is a template in Xcode for a navigation based app. It does everything you describe. Well, very close at least, only the AnotherViewController in -tableView:didSelectRowAtIndexPath: is commented out.
I have a UIPopOverController that shows a UIViewController with a UITableview in its view. The cells in the table have a detailedView, but whenever that view gets pushed, the PopOverController increases in size, and I am left with all this white space inside it.
Question is this: Can anyone show me how I can have a Master/Detail UITableview show inside a PopOverController whilst preserving its dimensions?
Some of my code if it helps you:
//Creating the PopOver with the UIViewController
addTaskViewController = [[AddTaskViewController alloc] initWithNibName:#"AddTaskViewController" bundle:nil];
UINavigationController *addTaskNavController = [[UINavigationController alloc] initWithRootViewController:addTaskViewController];
UIPopoverController *addTaskPopOver = [[UIPopoverController alloc] initWithContentViewController:addTaskNavController];
self.addTaskPopOverController = addTaskPopOver;
addTaskPopOverController.delegate = self;
//...neccessary releases...
//Showing the popover when a button is pressed
- (void) addTasksButtonPressed:(id)sender {
//Display the Popover containing a view from AddTaskViewController
[self.addTaskPopOverController setPopoverContentSize:CGSizeMake(400, 700)];
[addTaskPopOverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
You should set the detail view controller's contentSizeForViewInPopover property to the same value as the parent controller.