I am working on a tabbar project and in this i also have navigation controller. and i am doing below steps :-
Show the main screen
navigation from first tab to 5 next screens.
and on the 6th screen i want to show the tabbarcontroller and want to show my other tab bar.
i tried the below code :-
self.navigationController.tabBarController.hidesBottomBarWhenPushed = YES;
and some others. but did not get any success yet. so can any one suggest how to i do this?
Thanks
Create two files .h and .m without .xib
//.h file
#import <UIKit/UIKit.h>
#class Class1, Class2;
#interface TabbarController : UITabBarController
{
Class1 *class1;
Class2 *class2;
UINavigationController *nav1,*nav2;
}
#end
//.m file
#implementation TabbarController
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
class1 =[[Class1 alloc] initWithNibName:#"Class1" bundle:nil];
nav1=[[UINavigationController alloc] initWithRootViewController:class1];
class1.title = #"class1";
class1.tabBarItem.image = [UIImage imageNamed:#"tab1.png"];
class1.navigationController.navigationBar.hidden = TRUE;
class2 =[[Class2 alloc] initWithNibName:#"Class2" bundle:nil];
nav2=[[UINavigationController alloc] initWithRootViewController:class2];
class2.tabBarItem.image = [UIImage imageNamed:#"tab2.png"];
class2.title = #"class2";
class2.navigationController.navigationBar.hidden = TRUE;
NSArray *controllers = [NSArray arrayWithObjects:nav1,nav2,nil];
self.viewControllers = controllers;
}
Redirect your view to this view wherever you need tabbar.
TRy it by this:
Create the Object of Delegate class
#import "DelegateClass.h"
DelegateClass *appDel;
Now in .m class
-(void)viewDidLoad
{
[super viewDidLoad];
appDel= (DelegateClass *)[[UIApplication sharedApplication]delegate];
}
Now just do like this in the View from where you are navigation,
appDel.tabBarController.hidesBottomBarWhenPushed = YES;
This was just a tricky part.It worked greatly for me :)
You have to use custom UItabBarController.
see creating custom TabBar Controller
Related
I'm fairly new to xcode, but i'm having some trouble adding admob to my app.
I followed the instructions for Admob but the ads are not showing up.
Im thinking i need to add the new view i created AdViewController to appsdelegate. Is there a code i should add for that?
BTW: Im using a tabbar controller as the rootviewcontroller
In the view controller in which you want to display the add , do the following :
.h
#interface MyViewController: UIViewController
{
GADBannerView *adBanner;
}
#end
.m
#implementation MyViewController
// In the viewDidLoad method of the controller create a adbanner
-(void) viewDidLoad
{
[super viewDidLoad];
adBanner_ = [[GADBannerView alloc] initWithFrame:CGRectMake(0, 0, GAD_SIZE_320x50.width, GAD_SIZE_320x50.height)];
adBanner_.delegate = self;
adBanner_.rootViewController = self;
adBanner_.adUnitID = the_ad_ID_given_by_Google;
GADRequest *request = [GADRequest request];
[adBanner loadRequest:request];
[self.view addSubview:adBanner];
}
#end
You need to set the rootViewController to be the UITabBarController, but you need to add the GADBannerView object into the view for the view Controller that's currently being shown.
There's an example using a custom UITabBar solution here.
I first like to load simple viewController which shows some option and then clicking on some button I would like to load navigationController or tabbarController depending on button click. How can I do this ?
I replace the root view controller on the window when I want to switch the views.
For example in my app I show a loading screen first then I switch the view to a login screen.
To do this you need a reference to your app delegate then you can access the window property and replace the root view controller:
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
LoginViewController *loginVC = [[LoginViewController alloc] init];
appDelegate.window.rootViewController = loginVC;
In your simpleViewController :
- (IBAction) yourButtonAction:(id)sender
{
UIViewController *Vc = [[theViewControllerYouWantToShow alloc]init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:Vc];
[self presentModalViewController:nav animated:YES];
}
Edit :
you have three options to show your viewController content :
as the example above using presentModalViewController:
add the viewController view as a subView to the current viewController.
in your case : [simpleViewController.view addSubView:nav.view];
3.or if your simple ViewController is the navigation root viewController you can push other viewControllers to its navigation stack.
in appdelegate.h
#property (strong, nonatomic) id<UIApplicationDelegate>delegate;
in appdelgate.m
#synthesize delegate;
in my first viewController's .h file
AppDelegate *myappDelegate;
-(IBAction)start:(id)sender;
in my first viewController's .m file
-(IBAction)start:(id)sender
{
NSLog(#"Start Button is clicked");
mvc = [[MasterViewController alloc]initWithNibName:#"MasterViewController" bundle:nil];
myappDelegate = [[UIApplication sharedApplication]delegate];
myappDelegate.navigationController = [[UINavigationController alloc]initWithRootViewController:mvc];
myappDelegate.window.rootViewController = myappDelegate.navigationController;
[myappDelegate.window makeKeyAndVisible];
}
I have created a navigation-based application. In that, I have created MyTableViewController using uiviewcontroller.class.
#import "RootViewController.h"
#import "MyTableViewController.h"
#implementation RootViewController
- (void)viewDidLoad
{
[super viewDidLoad];
MyTableViewController *tableViewController = [[MyTableViewController alloc] init];
}
#end
#import "MyTableViewController.h"
#implementation MyTableViewController
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"sedfsdsd");
}
#end
I don't want to show the view when the instance is created. I want to call the constructor method. I don't know how to do it. Please help me out.
#Caroline have described very good.
A normal method of your class could serve your purpose and you can name that something ViewContruction and define it in your MyTableViewController class.
-(void) ViewContruction
{
//Create all your views here
//Add that to the self.view of your controller
}
Call the above function explicitly on the instance of your view controller.
Just creating a UIViewController instance does not load the view.
If you have something like [self.view addSubview:tableViewController.view] then when that statement is executed, viewDidLoad will get executed.
However, if it's a navigation-based app, then you will need to push the viewcontroller to see it, rather than adding the subview as above.
For example:
Settings *settingsController = [[Settings alloc] initWithNibName:#"Settings" bundle:nil];
settingsController.contentSizeForViewInPopover = settingsController.view.frame.size;
[self.navigationController pushViewController:settingsController animated:YES];
[settingsController release];
I use original method XML data can show in rootviewcontroller TableView. When i use New Procedure it show the table only no data. How can i show the data in New Method?
Original Method
appDelegate.m (setup XML & load the data)
rootviewController.m (use nsarray & load the data into table view)
New Method
appDelegate.m (setup XML & load the data)
mainviewController.m (Setup up UIVEW & button key), (when button press, go to rootviewcontroller.m)
rootviewController.m (use nsarray & load the data into table view)
appDeleagte.m
- (void)addbookToList:(NSArray *)books {
[self.rootViewController insertBooks:books];
mainviewcontroller.h
#import <UIKit/UIKit.h>
#class RootViewController;
#interface MainViewController : UIViewController {
IBOutlet RootViewController *rvController;
}
- (IBAction) startButton;
#end
mainviewcontroller.m
-(IBAction)startPage {
rvController = [[RootViewController alloc] initWithNibName:#"RootView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:rvController animated:YES];
rootviewcontroller.m
- (void)viewDidLoad {
[super viewDidLoad];
self.bookList = [NSMutableArray array];
self.tableView.rowHeight = 60.0;
[self addObserver:self forKeyPath:#"bookList" options:0 context:NULL];
}
If you call addBookToList: in your app delegate at a time that the root view controller doesn't yet exist, nothing will happen (sending message to nil). Store the books array, and pass it to your root view controller after you've created it, but before you push it onto the stack in your navigation controller.
I have a UIView that is pushing a UITableViewController that is contained inside of a UITabBarController.
#import <UIKit/UIKit.h>
#interface ARViewController : UITableViewController<UITabBarControllerDelegate> {
IBOutlet UITabBarController* tabBarController;
}
#property(nonatomic,retain)IBOutlet UITabBarController* tabBarController;
#end
Here is my implementation
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
self.clearsSelectionOnViewWillAppear = NO;
self.title = #"AR";
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
tabBarController.delegate = self;
[self.view addSubview:tabBarController.view];
}
My UITabBarController is referenced to Files Owner. Why is it not appearing?
UITabBarController is always used as 'root controller'. Maybe you can try to use a root controller to contain a tableview. And it's not a common method to add a tabbar as a subview to a tableview.