Created a TabBar Controller programmatically - but where is the xib file? - objective-c

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

Related

Upside down Orientation issue in iOS6

I am creating a sample empty application and added UIViewController class,
Below is the code in the App delgate
TestViewController* viewController = [[TestViewController alloc] initWithNibName:#"TestViewController" bundle:nil];
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:viewController];
[self.window setRootViewController:navController];
Now i am rotating the App but in the UPsidedown Orientation Navigation bar is not Rotating I am attaching a screen shot
Then Added a the Below Method in App delegate
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskAll;
}
And in the Class i have added following methods
-(BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskAll);
}
In the Summary i have activated all the orientations can any One tell me the Solution for it
1) just You created a category for UINavigationController class and I defined these methods
In CustomViewController.h
#import <UIKit/UIKit.h>
#interface CustomViewController : UINavigationController
#end
In CustomViewController.m
#import "CustomViewController.h"
#interface CustomViewController ()
#end
#implementation CustomViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(BOOL) shouldAutorotate{
return YES;
}
-(NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll;
}
And AppDelgate.m file
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
CustomViewController *navController = [[CustomViewController alloc] initWithRootViewController:self.viewController];
// Override point for customization after application launch.
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
2) And check Orientation In Target
3) Change the class from UINavigationController to the CustomViewController in my XIB in IB
4) Reset the Simulator and run the code, I think your problem will be solve.
i think you need to use
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return TRUE;
}
instead of shouldAutorotate
Upside Down button to ON in Supported interface orientations on Xcode
http://www.appcoda.com/ios-game-tutorial-maze-part-1/
`TestViewController* viewController = [[TestViewController alloc] initWithNibName:#"TestViewController" bundle:nil];
[self.window setRootViewController:viewController];`
remove the navigatioan bar from appdelegate and then check

PopoverController - deallocated instance

when I click the popover button in my splitviewcontroller, I receive the message: message sent to deallocated instance 0x6a66ca0
I already found out that this instance has to be the detailviewcontroller I allocate and init. So far so good. But I don't see the problem while the whole thing is not working.
First of all the AppDelegate where I create the Splitview:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// TestViews for SplitViewController
// TestView1 *test1 = [[TestView1 alloc] initWithNibName:#"TestView1" bundle:nil];
// TableView as RootViewController for the Left Hand Pane
RootViewTableViewController *rootViewTableViewController = [[RootViewTableViewController alloc] initWithNibName:#"RootViewTableView" bundle:nil];
UINavigationController *rootNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewTableViewController];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:rootNavigationController,detailNavigationController, nil];
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
return YES;
}
First I was thinking the code line self.splitviewcontroller.delegate = detailviewcontroller; could be the problem..... but the whole app starts up perfectly. only when i click the button this prob appears.
the RootViewController is this ( I omitted the standard tableview delegate methods for clarity)
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Set Title of the TableView for the RootViewController
self.title = #"Notarzteinsatzprotokoll";
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
}
NSLog(#"INIT %p", self);
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionMiddle];
}
and the detail view controller:
#pragma mark -
#pragma mark Managing the Detail Item
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view
[self configureView];
}
if (self.rootPopoverController != nil) {
[self.rootPopoverController dismissPopoverAnimated:YES];
}
}
- (void)configureView
{
// Update the user interface for the detail item
if (self.detailItem) {
self.detailDescriptionLabel.text = [self.detailItem description];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setTitle:#"Notarzteinsatzprotokoll"];
[self configureView];
}
#pragma mark -
#pragma mark Rotation Support
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return YES;
}
#pragma mark -
#pragma mark SplitView
- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc {
barButtonItem.title = #"Master";
[self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
self.rootPopoverController = pc;
}
- (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController *)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
[self.navigationItem setLeftBarButtonItem:nil animated:YES];
self.rootPopoverController = nil;
}
I don't see the point the program flow where the detailviewcontroller objects is released and something else tries to send a message... do I have to interchange some code lines?
Thank you!
Sebastian
#end
the error should tell you what message is being sent to a deallocated instance. Not sure exactly what the issue is, is it a setTitle: message being sent to the left bar button item?
In splitViewController:willShowViewController: you set the left bar button item to nil (which will dealloc it) and in splitViewController:willHideViewController: you attempt to changed its title, which could be your problem.

How to set title to tab bar item programatically?

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"];

UITableViewController bottom toolbar does't work?

I have UINavigationController and UITableViewController as root.
myViewController = [[MyViewController alloc] init];
UINavigationController * navContr = [[UINavigationController alloc] initWithRootViewController:myViewController];
[self.window addSubview:[navContr view]];
I need bottom toolbar with buttons for MyViewController view. Found in google that I should set:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
[self.navigationController setToolbarHidden:NO];
}
return self;
}
But there is no bottom toolbar in my TableView. What should I do???
Google said that?
Try starting over and make a Tab Bar Controller. http://www.panolee.com/antonimasso/tutorials/tab-bar-application
Then add a TableViewController to it.

UINavigationController with TTNavigator

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?