I am using a UINavigationController in the appdelegate as a basis for all views and I am using the TTNavgitor for antother flow starting with a TTTableViewController.
When I use the TTNavigator for some reason I have 2 problems:
After I choose one of the rows there is no back button in the viewcontroller loaded
The transition is not animated when selecting a row in the table
I am using the basis of the Three20 examples:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
self.title = #"Settings";
self.navigationItem.backBarButtonItem =
[[[UIBarButtonItem alloc] initWithTitle:#"Settings" style:UIBarButtonItemStyleBordered
target:nil action:nil] autorelease];
self.tableViewStyle = UITableViewStyleGrouped;
TTNavigator* navigator = [TTNavigator navigator];
navigator.supportsShakeToReload = YES;
navigator.persistenceMode = TTNavigatorPersistenceModeNone;
navigator.window = self.view.window;
TTURLMap* map = navigator.URLMap;
[map from:#"*" toViewController:[TTWebController class]];
[map from:#"tt://login" toViewController:[LoginController class]];
}
return self;
}
Does some has an idea why do I have these problems? and how can I solve this fast without rewriting all of the code?
Related
I've read selector as parameter in IOS post. However, I want to extend the question.
In my case, I'm creating an Objective-C (not Swift) Master/Detail application, and want to create DetailController object of type UIViewController with the following init function
In DetailViewController.h
#interfact DetailViewController : UIViewController
- (id)initWithNibName:(NSString *)nibName withSaveSelector:(SEL)saveSelector
#end
... and in DetailViewController.m
- (id)initWithNibName:(NSString *)nibName withSaveSelector:(SEL)saveSelector
{
self = [super initWithNibName:nibName bundle:nil];
if (self) {
UIBarButtonItem *done = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:saveSelector];
[[self navigationItem] setRightBarButtonItem:done animated:YES];
}
return self;
}
NOW, I want to just keep re-using above code to create different DetailViewControllers, and want to pass a saveSelector function that will get called when the user presses the "Done" button.
Now I have another view controller
#interface AnotherViewController : UIViewController
- (void)saveSelector:(id)sender;
#end
...and then in yet another object (i.e., NOT in AnotherViewController.m code), I use the above view controller, like so...
AnotherViewController *avc = [[AnotherViewController alloc] init];
DetailViewController *dvc = [[DetailViewController alloc] initWithNibName:#"AnotherViewController" withSaveSelector:#selector(???)];
What should I put in the ??? so I can pass AnotherViewController::saveSelector() function to DetailViewController?
I hope that makes sense.
Change your method as:
- (id)initWithNibName:(NSString *)nibName withSaveSelector:(SEL)saveSelector forTarget:(id)target
And call it like this:
DetailViewController *dvc = [[DetailViewController alloc] initWithNibName:#"AnotherViewController" withSaveSelector:#selector(saveSelector:) forTarget:avc];
In DetailViewController.m
- (id)initWithNibName:(NSString *)nibName withSaveSelector:(SEL)saveSelector forTarget:(id)target
{
self = [super initWithNibName:nibName bundle:nil];
if (self) {
UIBarButtonItem *done = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:target
action:saveSelector];
[[self navigationItem] setRightBarButtonItem:done animated:YES];
}
return self;
}
I implemented a TabBar Controller, it is initalised like this
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
firstView = [[FirstView alloc]init];
secondView = [[SecondView alloc]init];
firstItem = [[UITabBarItem alloc]initWithTitle:#"First" image:nil tag:0];
secondItem = [[UITabBarItem alloc]initWithTitle:#"Second" image:nil tag:1];
firstView.tabBarItem = firstItem;
secondView.tabBarItem = secondItem;
NSArray *viewArray = [[NSArray alloc]initWithObjects:firstView, secondView, nil];
[self setViewControllers:viewArray];
}
return self;
}
In the AppDidFinishedLoading I just did this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
mainbarController = [[MainBarController alloc]initWithNibName:#"MainBarController" bundle:nil];
[self.window setRootViewController:mainbarController];
[self.window makeKeyAndVisible];
return YES;
}
My problem is, I want to place the tabBar somewhere else, not at the bottom, as it is when I run the project. But I can´t find a xib File to my code. The mainwindow.xib is just an empty window. I know it´s very basic but I´m confused about this.
thanks anyway
I try this but it not works I can not see tab bar item..How can I solve this problem? Thanks for your help.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
myTabBarController = [[UITabBarController alloc] init];
tab1 = [[ZiyaretFormTab1 alloc] initWithNibName:#"ZiyaretFormTab1" bundle:nil];
tab2 = [[ZiyaretFormTab2 alloc] initWithNibName:#"ZiyaretFormTab2" bundle:nil];
tab3 = [[ZiyaretFormTab3 alloc] initWithNibName:#"ZiyaretFormTab3" bundle:nil];
tab4 = [[ZiyaretFormTab4 alloc] initWithNibName:#"ZiyaretFormTab4" bundle:nil];
tab5 = [[ZiyaretFormTab5 alloc] initWithNibName:#"ZiyaretFormTab5" bundle:nil];
myTabBarController.viewControllers = [NSArray arrayWithObjects: tab1, tab2,tab3,tab4,tab5,nil];
UITabBarItem *tabItem = [[[myTabBarController tabBar] items] objectAtIndex:1];
[tabItem setTitle:#"theTitle"];
[self.view addSubview:myTabBarController.view];
myTabBarController.selectedIndex=0;
}
In each of your view controllers that go into the tabs (ZiyaretFormTab1 to ZiyaretFormTab5), insert this code into initWithNib or viewDidLoad functions.
UITabBarItem * tabtitle = [[UITabBarItem alloc] initWithTitle: #"title"
image: nil //or your icon
tag: 0];
[self setTabBarItem: tabtitle];
Tab bar titles are controlled by their respective view controllers. The easiest way to set the title is from within the view controller for that tab, instead of trying to set it in the tab directly.
Each view controller has a title property which is used to set the title in tab bars and navigation bars. It also has a tabBarItem property which has it's own title property that you can set if you want to just set the tab and not affect navigation bars.
So in the viewDidLoad of your viewController, you could write:
self.tabBarItem.title = #"theTitle";
Put the tab settings to AppDelegate.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Put your name and icon information uniforms visit here:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = #"Kulağını tersten tutmana gerek yok";
self.tabBarItem.image = [UIImage imageNamed:#"ringtab.png"];
}
return self;
}
Have you tried to set
[tab1 setTitle:#"Your Title"]
after allocating and initialising it.
UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex:0];
[item setTitle:#"fgfdgd"];
I'm trying to customize UITabBarItem but I'm having problems with the image's position.
The image size is 81px x 49px, the same height as the UITabBar. This is how I set the image:
// AppDelegate
BlocosController *blocos = [[[BlocosController alloc] initWithManagedObjectContext:moc] autorelease];
UINavigationController *navBlocos = [[[UINavigationController alloc] initWithRootViewController:blocos] autorelease];
tabBarController = [[UITabBarController alloc] initWithManagedObjectContext:moc];
tabBarController.viewControllers = [NSArray arrayWithObjects: navData, navBlocos, navBairro, navAtualizar, nil];
// ...
// BlocosController.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.tabBarItem = [[[UITabBarItem alloc] initWithTitle:TITLE image:nil tag:10] autorelease];
[[self tabBarItem] setFinishedSelectedImage:[UIImage imageNamed:#"tab_bar_blocos_selected"] withFinishedUnselectedImage:[UIImage imageNamed:#"tab_bar_blocos_unselected"]];
}
return self;
}
I've search on google and found this tutorial, the code uses the same API as I use and works as expected. The code in this article behaves just like mine, but since their background is the same color there's a illusion of it been correctly placed.
Why is the finishedImageSelected and the unselected are placed unaligned with the tab tab? How to fix it?
I've found the correct way to accomplish this and made a post: felipecypriano.com/2012/02/27/….
Basically the problem is that finishedImage is the icon not the icon and the background, it's possible to use with the background by adjusting the imageInset property.
I try create tab bar controller programatically, it works but I can not set title to ta bar items. I can not see title when I running my application. My code is here. Please help me, what is the problem?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
myTabBarController = [[UITabBarController alloc] init];
view2Controller = [[testView alloc] init];
view3Controller = [[testView2 alloc] init];
view4Controller = [[testView3 alloc] init];
view5Controller = [[testView4 alloc] init];
view6Controller = [[testView5 alloc] init];
myTabBarController.viewControllers = [NSArray arrayWithObjects: view2Controller, view3Controller,view4Controller,view5Controller,view6Controller,nil];
UITabBarItem *tabItem = [[[myTabBarController tabBar] items] objectAtIndex:1];
[tabItem setTitle:#"theTitle"];
[self.view addSubview:myTabBarController.view];
myTabBarController.selectedIndex=0;
}
Set the title of ur viewcontroller in side viewcontroller's viewwillappear/disappear and it will be displayed in ur tabbaritem.
You can set the title of UIViewController, which reflects when it is pushed in UINavigationController or a UITabBarController. But you should set the title before putting it inside any of them.
init is generally a good place to set the title.
- (id)init {
// ... other code including check for self
self.title = #"My Title";
return self;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// self.title = #"My Title";
}
self.title = #"My Title";
return self;
}
Use above code in every subviews of tabbar controllers.
This may be help.
use this code
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title=#"FREE BOOKS";
self.tabBarItem.image = [UIImage imageNamed:#"first"];
}
return self;
}
Here is the tutorial from the scratch which should help you to achieve the exact functionality you want to achieve. Download the source code and run it directly and if title are correct the you can follow the tutorial to get the proper understanding of the flow of UITabBarController.
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.async {
self.tabBar.items?[0].title = "Title"
}
}
OR
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.tabBar.items?[0].title = "Title"
}