I am using the TTTableView class from the Three20 framework to create table view cells with styled content, including HTML with URLs. The cells look and work almost fine. The URL are picked up, and tapping on one of the fire the appropriate delegate method. However, the URL is open in a TTWebController the TTWebController does not have a back arrow to pop the view of the navigation stack.
Heres my code:
TTTableStyledTextItem *messageItem = [TTTableStyledTextItem itemWithText:[TTStyledText textFromXHTML:message lineBreaks:YES URLs:YES]];
messageItem.delegate = self;
TTListDataSource *dataSource = [[TTListDataSource alloc] init];
[dataSource.items addObject:messageItem];
TTNavigator* navigator = [TTNavigator navigator];
navigator.delegate = self;
navigator.window = [UIApplication sharedApplication].delegate.window;
TTURLMap* map = navigator.URLMap;
[map from:#"*" toViewController:[TTWebController class]];
self.tableView.dataSource = dataSource;
self.tableView.delegate = self;
The URLs are highlighted in the cells and tapping one fires this method:
- (BOOL)navigator: (TTBaseNavigator *)navigator shouldOpenURL:(NSURL *) URL {
return YES;
}
The TTWebController does not seem to be pushed onto the navigation stack, it is just "shown" without a back arrow. Any thoughts?
Update with my solution
After playing around some more I think the problem is is that I am trying to use the Three20 URL navigation method to push a new view controller while at the same time using a regular iOS UINavigationController. The point at which the TTWebcontroller is being shown is the first view controller on the Three20 navigation stack, and as such is the root view controller and so does not have any notion of "going back" to a previous view.
Here is my work around:
- (BOOL)navigator: (TTBaseNavigator *)navigator shouldOpenURL:(NSURL *) URL {
// setup a webcontroller with the URL and push it
TTWebController *webController = [[TTWebController alloc] init];
[webController openURL:URL];
[self.navigationController pushViewController:webController animated:YES];
[webController release];
// dont navigate with TTBaseNavigator
// this does not use the regular UINavigation stack and
// ... the new view becomes rootview and has no back button
return NO;
}
Hope this helps some one.
That might happen depending on how you presented the viewController containing the tableView. It that viewController pushed onto a UINavigationController or invoked per url (in that case Three20 would automatically create a navigationController for you).
You need to make sure, that a navigationController onto with the WebController can be pushed exists.
Related
So I'm trying to convert a single view application into a tabbed application. My use case is this - in one of the view controllers I want to push a new view controller and still have the tab underneath.
I'm currently doing this -
[self.tabBarController setViewControllers:#[self.searchViewController, self.loginViewController]];
[self.searchViewController presentViewController:self.searchViewController.detailController animated:YES completion:nil];
However, this makes the tab across the bottom disappear.
What should I do?
presentViewController is a "modal" presentation - the presented view controller takes over the entire screen. If you want to remain within the tab but move between view controllers, the root view controller in the tab should be a UINavigationController. You can then push/pop view controllers onto that.
There are two primary methods for view navigation, the first is a presentation which displays a view from the bottom that slides up, and the second is a push which displays a view from the right that slides in from the side.
In most cases, the view I am going to display and what action kicked off the navigation determine which method I will use. For example, if I have a table view that has a list of music albums and I want to search for a song by a particular artist, to see the songs within that album I want to PUSH the view controller, i.e. slide to the right. This gives me the built-in (and intuitive) ability to go back via the automatically added back button on the navigation bar in case the song I was looking for wasn't in the album I selected.
If perhaps I wanted to present the user with the ability to edit the album details, such as renaming the album, this is a totally different type of action, and I would want to PRESENT such a view modally, i.e. from the bottom.
The major distinction between the two is where are you going and what are you doing. If the next view you are going to show is something that does one action and you are then returned back to the original view, presenting modally from the bottom is conventional. If you are doing to be potentially navigation further and further into subsections and will be coming back and forth between said subsections, like Artist->Album->Song etc., you are going to want to push the view from the side, just like the default music app in iOS does.
This is an example starter project I created that demonstrates an easy way to make this work the way you likely want. I create instances of the different view controllers I want to be contained in the tabBarController, which are associated with the tabs, and then "wrap" them each with their own navigation controller before adding them to the tabBar via the .items property. This way each view controller has its own navigation hierarchy and within each you'll be able to call [self.navigationController pushViewController:] or [self.navigationController presentViewController] to keep the navigation 'within' the views and separate from the tabBar itself.
#import "AppDelegate.h"
#import "TabBarViewController.h"
#import "InfoViewController.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
InfoViewController *firstVC = [[InfoViewController alloc] init];
firstVC.title = #"First";
firstVC.view.backgroundColor = [UIColor redColor];
UINavigationController *firstNC = [[UINavigationController alloc] initWithRootViewController:firstVC];
InfoViewController *secondVC = [[InfoViewController alloc] init];
secondVC.title = #"Second";
secondVC.view.backgroundColor = [UIColor blueColor];
UINavigationController *secondNC = [[UINavigationController alloc] initWithRootViewController:secondVC];
TabBarViewController *tabBarVC = [[TabBarViewController alloc] init];
tabBarVC.viewControllers = #[firstNC, secondNC];
self.window.rootViewController = tabBarVC;
[self.window makeKeyAndVisible];
return YES;
}
That resulted in the following:
Hope that helps!
Hopefully someone can help.
I've got an app that uses the UISplitViewController however I've now had to start using multiple storyboards because i've got a large amount of views and Xcode was starting to run really slow. I've moved moved the UIViewControllers to multiple storyboards.
The Master View is built from static cells, so when the user selects the cell I normally change the view by pushing a segue.
I'm now wondering how to programmatically change the detail view of a UISplitViewController?
Thanks
Subclass UISplitViewController and set your root splitViewController to that class. Then add this method to your UISplitViewController subclass:
-(void)setDetailControllerTo:(UIViewController *)detailController withNavControllerTitle:(NSString *)title {
[detailController view]; // this line forces the viewDidLoad method to be called
if (title) {
UINavigationController *navController = [[UINavigationController alloc] init];
[navController pushViewController:detailController animated:YES];
detailController.title = title;
NSArray *viewControllers=#[self.mainController.viewControllers[0],navController];
self.mainController.viewControllers = viewControllers;
} else {
NSArray *viewControllers=#[self.mainController.viewControllers[0],detailController];
self.mainController.viewControllers = viewControllers;
}
}
To call this method do something like this from the master view controller:
FixedSplitViewController *splitController = (FixedSplitViewController*) self.splitViewController;
CurrentEventViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"CurrentEventViewController"];
// add any setup code here
[splitController setDetailControllerTo:controller withNavControllerTitle:#"Current Event"];
A lot of my projects require the splitviewcontroller to always show the master view so I use this subclass to keep the master view from hiding on portrait rotation.
So in my universal app I have a section where a person can look at an existing list of notes from our system (retrieved through a simple web service) and then also create a new note if they want. So for the iphone it's pretty simple layout, a TableViewController for displaying the list with a "Add" button on the NavigationBar that presents the modalview for adding the new item. On the iPad though, the same layout has a lot of wasted space so I opted to go with the popOver method to show the list in a popOver and then let them add from there. My problem is that when the user clicks on the Add button within the PopOver view, the modal view comes up full screen instead of just coming up within the popover view. Here's the code I have so far:
-(void) AddButtonPressed:(id)sender {
NewNoteVC *newNote = [[[NewNoteVC alloc] initWithNibName:#"NewNoteVC" bundle:nil] autorelease];
newNote.defaultClientID = defaultClientID;
UINavigationController *navCon = [[[UINavigationController alloc] initWithRootViewController:newNote] autorelease];
if ([isPopOver isEqualToString:#"YES"]) {
[navCon setModalInPopover:YES];
[self.navigationController setModalInPopover:YES];
[self.navigationController presentModalViewController:navCon animated:YES];
}
else {
[self.navigationController presentModalViewController:navCon animated:YES];
}
}
The "isPopOver" string is just a placeholder sent from the previous screen that called this TableView (I know I can switch this to a boolean for better performance I just put this together real quick to try it out). I know I messed up somewhere, I just don't know what setting I need to get this working correctly.
You need to define the view controller's modalPresentationStyle to be "current context".
navCon.modalPresentationStyle = UIModalPresentationCurrentContext;
This will result in modal view controller filling the popover like the popover's root controller.
Try using the presentViewController:animated:completion: instead of presentModalViewController:animated: and set self.navigationController.definesPresentationContext = YES
I'm trying to build the interface for an app that looks like this:
I want to use the Storyboard to create the views, but I'm having trouble figuring out how now. I've dropped a SplitViewController that is hooked up to 2 navigation controllers: MasterNavigationController, and DetailNavigationController (Master is the left side menu and Detail the right side).
I was starting to build all my ViewControllers in storyboard. Then build NSArrays to hold the various ViewController stacks needed for each of the Master's menu items. So when a user taps on a menu item, I'd load the corresponding ViewController stack into the DetailNavigationController using this method:
- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated
But now I'm thinking, I should create a separate DetailNavigationController for each of the menu items. For example:
RecentOrdersNavigationController
CustomersNavigationController
ItemsNavigationController
...
Then when a user taps a menu item, the entire DetailNavigationController changes to the appropriate one.
How should I be structuring the the interface while using storyboard?
Use a separate viewController for each detail view. You want your code to be separate since it can get confusing fast with all the different functionality for each view. From there, you can easily swap out the the detail.
Subclass UISplitViewController and set your root splitViewController to that class. Then add this method to your UISplitViewController subclass:
-(void)setDetailControllerTo:(UIViewController *)detailController withNavControllerTitle:(NSString *)title {
[detailController view]; // this line forces the viewDidLoad method to be called
if (title) {
UINavigationController *navController = [[UINavigationController alloc] init];
[navController pushViewController:detailController animated:YES];
detailController.title = title;
NSArray *viewControllers=#[self.mainController.viewControllers[0],navController];
self.mainController.viewControllers = viewControllers;
} else {
NSArray *viewControllers=#[self.mainController.viewControllers[0],detailController];
self.mainController.viewControllers = viewControllers;
}
}
To call this method do something like this from the master view controller in the tableView:didSelectRowAtIndexPath: method
FixedSplitViewController *splitController = (FixedSplitViewController*) self.splitViewController;
CurrentEventViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"CurrentEventViewController"];
// add any setup code here
[splitController setDetailControllerTo:controller withNavControllerTitle:#"Current Event"];
If you wish to keep the master view visible in portrait rotation, add this method to the SplitViewController subclass:
-(BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation {
return NO;
}
A lot of my projects require the splitviewcontroller to always show the master view so I use this subclass to keep the master view from hiding on portrait rotation.
Hi in VC1 I have an NSMutableArray displaying results. I want to keep that array alive even when users clicks to a different tab (so they don't have to search again) until the user searches again.
I have a strong pointer to it, but it seems to unload when I leave the view.
Not much code to show (_resultsArray is set from a previous controller using delegates, so it loads with the results already)
- (void)viewDidLoad
{
[super viewDidLoad];
_resultsTableView.dataSource=self;
_resultsTableView.delegate=self;
[self.navigationController.navigationBar setHidden:YES];
}
//then standard tableview delegate methods...
This code is to try to figure out how to segue tab bar to share info.
(in prepareforsegue)
Currently in Search VC. Now I have results I want to give to resultsIndexVC. The code below attempts this.
This is placed in current (search VC) prepare for segue.
ResultsIndexViewController* vc = [[ResultsIndexViewController alloc] init];
UITabBarController* tbc = [segue destinationViewController];
vc = (ResultsIndexViewController *)[[tbc customizableViewControllers] objectAtIndex:1];
vc.SearchDelegate=self;//crash here (normally works if using regular segue)
vc.resultsArray = _temporaryResultsArray;
vc.originalQuery=_queryArray;
Thanks
Issue is that I was pushing a VC. Instead I used the tabbar (which doesnt release the object when switching tabs)