i'm working on an application and i'm still a beginner with ios programing.
I'm asking for your help because i used the apple MasterDetailView template.
I'm generating a list of file stored in my application, which i display within my MasterView(TableView).
When i click on one of the files contained in my list i generate an image in relationship with this file and i would like to display it in my DetailView.
Is there a solution to do it without destroying all my application :)
Thanks for you help guys!!
This is my Delegate and how my controllers are declared:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.splitViewController = [[UISplitViewController alloc] init];
self.splitViewController.delegate = detailViewController;
self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];
self.window.rootViewController = self.splitViewController;
[self.window makeKeyAndVisible];
return YES;
}
Assuming it's your master controller that's responsible for creating the image.... You would normally create a property in your detail controller to hold a reference to the image. Inside the method tableView:didSelectRowAtIndexPath: of the master, you would pass that reference to the detail view controller.
(Alternatively, pass the file information instead and let the detail controller create the image.)
Related
I started a new Tabbed Application in XCode and I was wondering what the best way to add extra buttons to the given Tab Bar is?
Thanks!
As According to Xcode 4.3.3 When we Create Tabbed Application then it gives two ViewController. So if You want to add more you can go in AppDelegate and you can see
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] autorelease];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
And you can see Two ViewController are added in the tabBarController and You can create new one and add init as 1 or 2 were added.
Try .......
I am creating a tab bar application, but i want to create tab bar controller not in Main.xib by using interface builder. Because my app has no Main.Xib. So I either should do it in ViewController.xib or programmatically in a controller/appdelegate. I couldnt find any good tutorial or example for it.
In my app i have
AppDelegate.h
AppDelegate.m
ViewController.h
ViewController.m
ViewController.xib
My application starts with view of ViewController.xib know i want to add not a tab bar but a tab bar controller which will always stay bottom of views. How can i do that?
appdelagete.h
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
I have tried to do it programatically by looking at apple developer docs but couldnt figure it out.
Thanks in advance for any example code
I found this working great
appdelegate.h
#property (nonatomic, retain) UITabBarController *rootController
appdelegate.m
UIViewController *viewController1 = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
self.rootController = [[[UITabBarController alloc] init] autorelease];
self.rootController.viewControllers = [NSArray arrayWithObjects:viewController1, nil];
self.window.rootViewController = self.rootController;
This will create a tab bar with 3 views
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:view1, view2, view2, nil];
self.window.rootViewController = self.tabBarController;
///AppDelegate.m file : didFinishLaunchingWithOptions method
//initiate window
window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
//initiate viewcontrollers
FirstViewController *aFirstViewController = [FirstViewController new];
SecondViewController *aSecondViewController = [SecondViewController new];
aFirstViewController.tabBarItem.title = #"First";
aFirstViewController.tabBarIte
aSecondViewController.tabBarItem.title = #"Second";
gTabBarController = [[UITabBarController alloc]init];
gTabBarController.viewControllers = #[aFirstViewController ,aSecondViewController];
//show the main window and also make it key
[window makeKeyAndVisible];
window.rootViewController = gTabBarController;
i need to set action for my UITabbar, As when i click my tabbaritem it should go to an action which i am having in another viewcontroller.
but it is redirecting to UITableview
here is my code -
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// create our table view controller that will display our store list
FirstViewController *firstViewController = [[EzMasterViewController alloc] init];
// create the navigation controller that will hold our store list and detail view controllers and set the store list as the root view controller
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
[navController.tabBarItem setTitle:#"Home"];
[navController.tabBarItem setImage:[UIImage imageNamed:#"53-house.png"]];
SecondViewController *secondViewController = [[SecondViewController alloc] init];
// create the navigation controller that will hold our store list and detail view controllers and set the store list as the root view controller
UINavigationController *navController1 = [[UINavigationController alloc] initWithRootViewController:secondViewController];
[navController1.tabBarItem setTitle:#"Scan"];
[navController1.tabBarItem setImage:[UIImage imageNamed:#"195-barcode.png"]];
ThirdViewController *thirdViewController = [[ThirdViewController alloc] init];
// create the navigation controller that will hold our store list and detail view controllers and set the store list as the root view controller
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:thirdViewController];
[navController2.tabBarItem setTitle:#"Map"];
[navController2.tabBarItem setImage:[UIImage imageNamed:#"07-map-marker.png"]];
// add our view controllers to an array, which will retain them
NSArray *viewControllers = [NSArray arrayWithObjects:navController, navController1,navController2, nil];
// add our array of controllers to the tab bar controller
UITabBarController *tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:viewControllers];
// set the tab bar controller as our root view controller
[self.window setRootViewController:tabBarController];
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
return YES;
}
By clicking on SecondViewController tabbaritem it should redirect to the action,
where the action is in FirstViewController.
You should consider implementing the UITabBarControllerDelegate's two methods:
– tabBarController:shouldSelectViewController:
– tabBarController:didSelectViewController:
I started a project in Xcode 4.2 using tab view template. In the app delegate I added a third tab by code just like first and second tabs. Then I created a third view controller class with a nib file.
When I run this app, I see all three tabs but when I click on the third tab, it crashes.
I noticed the first and second nib files have a dark bar at the bottom(probably representing the tab bar) of the view but the new third nib file that I created lacks it. Any idea how I make this third tab work?
Thanks
This is how I add the third view controller.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1, *viewController2, *viewController3;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
viewController1 = [[FirstViewController alloc] initWithNibName:#"FirstViewController_iPhone" bundle:nil];
viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController_iPhone" bundle:nil];
viewController3 = [[ThirdViewController alloc] initWithNibName:#"ThirdViewController_iPhone" bundle:nil];
} else {
viewController1 = [[FirstViewController alloc] initWithNibName:#"FirstViewController_iPad" bundle:nil];
viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController_iPad" bundle:nil];
}
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
In the tab bar controller make sure the class of the view controller for the tab is the same as the view controller class you created.
Also check the logs, it will probably have a very informative message for you as to why it crashed.
Edit:
Never mind, you are passing in an un-initialized view controller for viewController3. Set all of those initial values to nil.
I was following this tutorial on http://www.youtube.com/watch?v=LBnPfAtswgw and was able to replicate that in XCode 3 however with XCode 4 I am having some issues.
My app's root view controller is a UITabBarController on which I selected one of the tabs and selected a UINavigationController and then dragged a view as the tutorial suggests but am unable to select my UITableViewController class?
I also do not see a section where it says to select a tab bar controller and select the UINavigation controller (around 9:08)
Can anyone guide me as to what I am doing wrong?
You can do the same by using the following code:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
TablelViewController *viewController1 = [[TablelViewController alloc] initWithNibName:#"TablelViewController" bundle:nil];
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
TableViewController2 *viewController2 = [[TableViewController2 alloc] initWithNibName:#"TableViewController2" bundle:nil];
UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:viewController2];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController1, navigationController2, nil];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
This code goes in:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions