Open UIViewController when clicking on TTTabIcon - iphone

can you tell me how I can open a UIViewController when I tab on a TTTabItem?
URL mapping is done in the app delegate:
TTNavigator* navigator = [TTNavigator navigator];
navigator.supportsShakeToReload = YES;
navigator.persistenceMode = TTNavigatorPersistenceModeAll;
TTURLMap* map = navigator.URLMap;
[map from:#"*" toViewController:[TTWebController class]];
[map from:#"tt://mannschaft" toViewController:[MannschaftController class]];
Then in my view controller I have successfully added my TTTabSTrip:
CGRect applicationFrame = [UIScreen mainScreen].applicationFrame;
self.view = [[[UIView alloc] initWithFrame:applicationFrame] autorelease];
self.view.backgroundColor = TTSTYLEVAR(tabTintColor);
_tabBar = [[TTTabStrip alloc] initWithFrame:CGRectMake(0, 0, applicationFrame.size.width, 41)];
_tabBar.tabItems = [NSArray arrayWithObjects:[[[TTTabItem alloc] initWithTitle:#"Anno 1834"] autorelease], nil];
[self.view addSubview:_tabBar];
How can I now open another uiviewcontroller below the TTTabStrip using the TTURLMap?
Thanks, doonot

Ok, I had to set my view controller as delegate first:
- (void)loadView {
CGRect applicationFrame = [UIScreen mainScreen].applicationFrame;
self.view = [[[UIView alloc] initWithFrame:applicationFrame] autorelease];
self.view.backgroundColor = TTSTYLEVAR(tabTintColor);
_tabBar = [[TTTabStrip alloc] initWithFrame:CGRectMake(0, 0, applicationFrame.size.width, 41)];
_tabBar.tabItems = [NSArray arrayWithObjects:[[[TTTabItem alloc] initWithTitle:#"Ajax Wälläbärg"] autorelease], nil];
_tabBar.delegate = self;
[self.view addSubview:_tabBar];
}
Then, if you click on a TTabItem, delegate calls this function:
- (void)tabBar:(TTTabBar*)tabBar tabSelected:(NSInteger)selectedIndex {
TTTabItem *tabItem = [tabBar.tabItems objectAtIndex:selectedIndex];
NSLog(#" tabItem:%#, tabItem.title::%#", tabItem, tabItem.title);
if(selectedIndex == 0){
UIViewController* viewController = [[TTNavigator navigator] viewControllerForURL:#"tt://ajax"];
[self.view addSubview:viewController.view];
[self.view addSubview:_tabBar];
}
}
The first item in the list is of course the item with index 0. Now you can define the url mapping in app delegate. For example tt://ajax calles the SponsorController:
UIViewController* viewController = [[TTNavigator navigator] viewControllerForURL:#"tt://ajax"];
ajax is defined in app delegate:
TTNavigator* navigator = [TTNavigator navigator];
navigator.supportsShakeToReload = YES;
navigator.persistenceMode = TTNavigatorPersistenceModeAll;
TTURLMap* map = navigator.URLMap;
[map from:#"*" toViewController:[TTWebController class]];
[map from:#"tt://mannschaft" toViewController:[MannschaftController class]];
[map from:#"tt://ajax" toViewController:[SponsorController class]];
I hope that helpes. Really bad that there are hardly no examples or tutorials out there. Cheers

Related

get reference of the application window in the succeeding classes IPHONE app

I am adding tab controller on my 4th screen. Up to 4th screen my navigation bar is visible
now on the 4th screen when i am adding Tab Controller to the window, navigation bar is getting disappeared...
code written in the tabbedController class is :
- (void)viewDidLoad
{
self.tabController = [[UITabBarController alloc]init];
FirstTabScreen *firstTab = [[FirstTabScreen alloc]initWithNibName:nil bundle:nil];
SecondTabScreen *secondTab = [[SecondTabScreen alloc]initWithNibName:nil bundle:nil];
firstTab.title=#"First";
firstTab.tabBarItem.image = [UIImage imageNamed:#"small_star.png"];
secondTab.title=#"second";
secondTab.tabBarItem.image = [UIImage imageNamed:#"small_star.png"];
tabController.viewControllers = [NSArray arrayWithObjects:
firstTab,
secondTab,
nil];
// self.tabWindow = [[[[UIApplication sharedApplication]keyWindow ]subviews ] lastObject];
//self.tabWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// self.tabWindow = [[UIApplication sharedApplication] keyWindow ];
//self.tabWindow = self.appDelegateAccess.window;
self.tabWindow = self.appDelegateAccess.window;
[self.tabWindow addSubview:tabController.view];
[self.tabWindow makeKeyAndVisible];
// [self.view addSubview:tabsContainer.view];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
Please let me know where I am going wrong....
i think I am not referencing the root window for adding the tab controller ..
it it is the case please suggest me the way to take root window for adding tab controller
Thanks
why are you adding the tabbarcontroller in the window. why dont you add it in self.view ?
First of all make object of tabBar in YourAppDelegate. And write following code in following methode
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.tabController = [[UITabBarController alloc]init];
FirstTabScreen *firstTab = [[FirstTabScreen alloc]initWithNibName:nil bundle:nil];
SecondTabScreen *secondTab = [[SecondTabScreen alloc]initWithNibName:nil bundle:nil];
firstTab.title=#"First";
firstTab.tabBarItem.image = [UIImage imageNamed:#"small_star.png"];
secondTab.title=#"second";
secondTab.tabBarItem.image = [UIImage imageNamed:#"small_star.png"];
tabController.viewControllers = [NSArray arrayWithObjects:
firstTab,
secondTab,
nil];
/*
Your Other Code
*/
}
Then in your third View controller's .m file import your appDelegate like..
#import "YourAppDelegate.h"
Last Step write following code on selecting a row of your third view controller...
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
YourAppDelegate * appDel = (YourAppDelegate *)[[UIApplication SharedApplication] delegate];
[appDel.window setRootViewController:appDel.tabController];
}
You need to add navigation controller separately,
Try this,
self.tabController = [[UITabBarController alloc]init];
FirstTabScreen *firstTab = [[FirstTabScreen alloc]initWithNibName:nil bundle:nil];
SecondTabScreen *secondTab = [[SecondTabScreen alloc]initWithNibName:nil bundle:nil];
UINavigationController *navControllerOne = [[UINavigationController alloc] initWithRootViewController: firstTab];
navControllerOne.navigationBar.tintColor = [UIColor blackColor];
navControllerOne.tabBarItem.image=[UIImage imageNamed:#"star.png"];
navControllerOne.tabBarItem.title = #"First";
UINavigationController *navControllerTwo = [[UINavigationController alloc] initWithRootViewController: secondTab];
navControllerTwo.navigationBar.tintColor = [UIColor blackColor];
navControllerTwo.tabBarItem.image=[UIImage imageNamed:#"star.png"];
navControllerTwo.tabBarItem.title = #"Second";
tabController.viewControllers = [NSArray arrayWithObjects:
navControllerOne,
navControllerTwo,
nil];
// self.tabWindow = [[[[UIApplication sharedApplication]keyWindow ]subviews ] lastObject];
//self.tabWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// self.tabWindow = [[UIApplication sharedApplication] keyWindow ];
//self.tabWindow = self.appDelegateAccess.window;
self.tabWindow = self.appDelegateAccess.window;
[self.tabWindow addSubview:tabController.view];
[self.tabWindow makeKeyAndVisible];
// [self.view addSubview:tabsContainer.view];
great !!!! it fixed ...
I have removed
self.tabWindow = self.appDelegateAccess.window;
[self.tabWindow addSubview:tabController.view];
[self.tabWindow makeKeyAndVisible];
and added only one line
[self.view addSubview:tabController.view];
Finally it worked !!!
Thanks Rohit ..

Unable to make animation in didFinishLaunchingWithOptions

I have this code in didFinishLaunchingWithOptions:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *myViewController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
self.window.rootViewController = myViewController;
[self.window makeKeyAndVisible];
I want to make a UIImageView to appear, play animation and disappear after that.
I'm adding this code to my existing code but nothing is happening:
UIImageView *imgView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
NSArray *animationFrames = [[NSArray alloc]initWithObjects:blablahblah, nil];
imgView.animationImages = animationFrames;
imgView.animationDuration = 1.5;
imgView.animationRepeatCount = 1;
What am I doing wrong here?
Thanks in advance!
Put your code in your ViewDidLoad.
.m
animation.animationImages = [NSArray arrayWithObjects:
[UIImageimageNamed:#"chicken1.tiff"],
[UIImageimageNamed:#"chicken2.tiff"],
[UIImageimageNamed:#"chicken3.tiff"],nil];
[animationsetAnimationRepeatCount:0];
animation.animationDuration = 1;
[animation startAnimating];
.h
IBOutlet UIImageView *animation;
In the view controller:
//use the view controller's frame
UIImageView *imgView = [[UIImageView alloc] initWithFrame:self.view.frame]];
NSArray *animationFrames = [[NSArray alloc]initWithObjects:blablahblah, nil];
imgView.animationImages = animationFrames;
imgView.animationDuration = 1.5;
imgView.animationRepeatCount = 1;
[self.view addSubview:imgView]; //Add the image view to the current view
to remove:
[imgView removeFromSuperview]; //call when animation is done

Delegate Methods Not Firing on Search Results Table

All,
I have a UITableView w/detail, with a Search bar, created from code. Works fine on selected items except it doesn't work when an item is clicked from the search results; no delegate methods fire. Never seen this type of behavior before so I don't know where the issue lies.
I get the same behavior with standard table cells as well as custom table cells.
Appreciate any guidance on this and thanks.
Just Hangs Here
//ViewController.h
#interface SongsViewController : UITableViewController <UISearchBarDelegate,UISearchDisplayDelegate>
{
NSMutableArray *searchData;
UISearchBar *searchBar;
UISearchDisplayController *searchDisplayController;
UITableViewCell *customSongCell;
}
//ViewController.m
-(void)viewDidLoad
{
[super viewDidLoad];
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 88)];
[searchBar setShowsScopeBar:YES];
[searchBar setScopeButtonTitles:[[NSArray alloc] initWithObjects:#"Title",#"Style", nil]];
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
self.tableView.tableHeaderView = searchBar;
//Load custom table cell
UINib *songCellNib = [UINib nibWithNibName:#"SongItem" bundle:nil];
//Register this nib, which contains the cell
[[self tableView] registerNib:songCellNib forCellReuseIdentifier:#"SongItemCell"];
// create a filtered list that will contain products for the search results table.
SongStore *ps = [SongStore defaultStore];
NSArray *songObjects = [ps allSongs];
self.filteredListContent = [NSMutableArray arrayWithCapacity: [songObjects count]];
self.masterSongArr = [[NSMutableArray alloc] initWithArray:[ps allSongs]];
[self refreshData];
[self.tableView reloadData];
self.tableView.scrollEnabled = YES;
}
I fixed this issue. I forgot to set this searchDisplayController delegates:
[searchDisplayController setSearchResultsDelegate:self];
So make sure you set All of these:
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
[searchDisplayController setDelegate:self];
[searchDisplayController setSearchResultsDataSource:self];
[searchDisplayController setSearchResultsDelegate:self];

Three20 doesn't show website in UIWebView

Hi all
I have a tabbar based application. In one view I have a TTTabStrip with different TTTabItems. Everything works (loading normal UIViewControllers) except loading UIWebViews.
In the app delegate I have set up the url mapping:
TTNavigator* navigator = [TTNavigator navigator];
navigator.supportsShakeToReload = YES;
navigator.persistenceMode = TTNavigatorPersistenceModeAll;
TTURLMap* map = navigator.URLMap;
[map from:#"*" toViewController:[TTWebController class]]; // default klasse wenn nichts anderes gewählt ist.
[map from:#"tt://test" toViewController:[TestController class]];
The test controller contains one UIWebView. I can see (NSLog) that the loadView-Method gets called, but the URL is not being opened:
- (void) loadView {
CGRect applicationFrame = [UIScreen mainScreen].applicationFrame;
self.view = [[[UIView alloc] initWithFrame:applicationFrame] autorelease];
//self.view.backgroundColor = [UIColor blackColor];
NSURL *theURL = [NSURL URLWithString:#"http://www.google.com"];
[webView loadRequest:[NSURLRequest requestWithURL:theURL]];
// support zooming
webView.scalesPageToFit = YES;
}
For instance, I can change the background of the UIWebView to black.
How can I load google in the web view below the TTTabStrip?
Thanks a lot.
Try the following and add the method viewWillAppear:
- (void)loadView
{
CGRect applicationFrame = [UIScreen mainScreen].applicationFrame;
UIView * newView = [[UIView alloc] initWithFrame:applicationFrame];
// support zooming
webView.scalesPageToFit = YES;
[newView addSubview:webView];
self.view = newView;
[newView release];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSURL *theURL = [NSURL URLWithString:#"http://www.google.com"];
[webView loadRequest:[NSURLRequest requestWithURL:theURL]];
}

UIToolbar and UINavigationController

I need to display a view modally. The viewcontroller that needs to be displayed modally has to have a UIToolbar at the bottom. In this toolbar there are one uisegmentedcontroller with three elements. (Think of an tabbar).
In the viewcontroller that presents the modal viewcontroller I have:
-(IBAction)presentModally:(id)sender {
if (self.nvc == nil) {
MyModalViewController *vc = [[MyModalViewController alloc] init];
UINavigationController *navvc = [[UINavigationController alloc] initWithRootViewController:vc];
navvc.navigationItem.prompt = #"";
navvc.navigationBar.barStyle = UIBarStyleBlack;
[vc release];
self.nvc = navvc;
[navvc release];
}
[self presentModalViewController:self.nvc animated:YES];
}
MyModalViewController:
- (void)loadView {
[super loadView];
UIView *uiview = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 460.0f)];
uiview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.view = uiview;
[uiview release];
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 436.0f, 320.0f, 44.0f)];
toolbar.barStyle = UIBarStyleBlack;
toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
NSArray *itemArray = [NSArray arrayWithObjects: #"One", #"Two", #"Three", nil];
UISegmentedControl *segCon = [[UISegmentedControl alloc] initWithItems:itemArray];
segCon.frame = CGRectMake(60, 4, 200, 36);
segCon.segmentedControlStyle = UISegmentedControlStyleBar;
segCon.tintColor = [UIColor darkGrayColor];
segCon.selectedSegmentIndex = 0;
[segCon addTarget:self action:#selector(changedSegment:) forControlEvents:UIControlEventValueChanged];
[toolbar addSubview:segCon];
self.segmentedControl = segCon;
[segCon release];
[[self navigationController].view addSubview:toolbar];
[toolbar release];
}
- (void)changedSegment:(id)sender {
UISegmentedControl *control = (UISegmentedControl *)sender;
int index = control.selectedSegmentIndex;
[[self navigationController] popViewControllerAnimated:NO];
[[self navigationController] pushViewController:[self.controllers objectAtIndex:index] animated:NO];
}
The viewcontrollers in the array are just normal UIViewControllers.
I have set this property in those classes to:
self.navigationItem.hidesBackButton = YES;
My question: Is this the proper way to achieve a UITabBarController behavior?
Haven't tested it, but It looks good, except that popViewControllerAnimated. I'd use popToRootViewControllerAnimated instead (In case a controller uses itself the navigationController).