SplitView navigation issue in ipad - iphone

i implemented a split view in my app. When my app launch it shows fine.
masterview=Leftside view & detailView = Home view
But my master view also contains 2 Table view. when i clicked the any row of table view, the detail view(Now, class view) is not get display.
Mean i want to disply display mutiple detail view as per master view's table row selected.
my code for split view is as follow:
// AppDelegate.h
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
LeftViewController *masterViewController = [[LeftViewController alloc] initWithNibName:#"LeftViewController_iPad" bundle:nil] ;
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController] ;
HomeViewController *detailViewController = [[HomeViewController alloc] initWithNibName:#"HomeViewController_iPad" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
masterViewController.home_Detail = detailViewController;
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];
}
//LeftView.m
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.appDelegate.splitViewController viewWillDisappear:YES];
NSMutableArray *viewControllerArray=[[NSMutableArray alloc] initWithArray:[[self.appDelegate.splitViewController.viewControllers objectAtIndex:1] viewControllers]];
[viewControllerArray removeAllObjects];
if (tableView==tbl_class)
{
self.class_VC=[[Class_Vice_ViewController alloc]initWithNibName:#"Class_Vice_ViewController" bundle:nil];
[[NSUserDefaults standardUserDefaults]setInteger:[[[classNames objectAtIndex:indexPath.row]valueForKey:#"class_id"]intValue] forKey:#"psel_class"];
NSLog(#"%d",[[[classNames objectAtIndex:indexPath.row]valueForKey:#"class_id"]intValue]);
[viewControllerArray addObject:self.class_VC];
self.appDelegate.splitViewController.delegate = self.class_VC;
[[self.appDelegate.splitViewController.viewControllers objectAtIndex:1] setViewControllers:viewControllerArray animated:NO];
[class_VC viewWillAppear:YES];
}
}
Help me to Solve this issue

The offending line is this one in the didSelectRowAtIndexPath: method:
[self.appDelegate.splitViewController viewWillDisappear:YES];
I don't know why you put that in, but if you remove it, it should work. You also don't need this line:
[self.class_VC viewWillAppear:YES];
While it is quite common to override viewWillAppear: and viewWillDisappear:, you almost never call them like you're doing.

Related

Detect selected tabbar when switching tab bar

I have three tab bar application and my tabs is TAB1, TAB2 , TAB3 i have write the following code in TAB1 view controller to detect which tab user have pressed
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
NSLog(#"tab selected: %#", item.title);
}
But this delegate never get called
i have setup my tab in appdelegate.m something like that
- (void)setupTabBar
{
self.myWorkListViewController = [[MyWorkListViewController alloc] initWithNibName:#"MyWorkListViewController"
bundle:nil];
self.askHRViewController = [[AskHRViewController alloc] initWithNibName:#"AskHRViewController"
bundle:nil];
self.moreViewController = [[MoreViewController alloc] initWithNibName:#"MoreViewController"
bundle:nil];
self.bookLeaveViewController = [[BookLeaveViewController alloc] initWithNibName:#"BookLeaveViewController"
bundle:nil];
self.helpViewController = [[HelpViewController alloc] initWithNibName:#"HelpViewController"
bundle:nil];
// Create navigation controllers
workListNavigationController = [[UINavigationController alloc] initWithRootViewController:self.myWorkListViewController];
askHRNavigationController = [[UINavigationController alloc] initWithRootViewController:self.askHRViewController];
bookLeaveViewController = [[UINavigationController alloc] initWithRootViewController:self.bookLeaveViewController];
moreNavigationController = [[UINavigationController alloc] initWithRootViewController:self.moreViewController];
helpNavigationController = [[UINavigationController alloc] initWithRootViewController:self.helpViewController];
[self setTabBarImagesAndText];
// Setup tab bar controller
self.tabBarController = [[UITabBarController alloc] init];
[self.tabBarController setViewControllers:[NSArray arrayWithObjects:workListNavigationController, askHRNavigationController, bookLeaveViewController, helpNavigationController,moreNavigationController, nil]];
//Set TabBar background
[self.tabBarController.tabBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"TabBar_iOS4_Background"]] atIndex:0];
[self.tabBarController setSelectedIndex:0];
}
you can detect selected Tabbar Item like this way:-
as par your code you just need to add this line
// Setup tab bar controller
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.delegate=self;
[self.tabBarController setViewControllers:[NSArray arrayWithObjects:workListNavigationController, askHRNavigationController, bookLeaveViewController, helpNavigationController,moreNavigationController, nil]];
//Set TabBar background
[self.tabBarController.tabBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"TabBar_iOS4_Background"]] atIndex:0];
[self.tabBarController setSelectedIndex:0];
in .h file define like
#interface yourViewcontroller : UIViewController<UITabBarControllerDelegate>
{
//declare your Tabbar controller with #proparty
}
in .m file
//#synthesize here your Tabbar controller
- (void)viewDidLoad
{
self.yourTabbarControler.delegate=self;
[super viewDidLoad];
}
and now put this delegate of UITabbarController
- (void)tabBarController:(UITabBarController *)tabBarController
didSelectViewController:(UIViewController *)viewController
{
NSLog(#"controller class: %#", NSStringFromClass([viewController class]));
NSLog(#"controller title: %#", viewController.title);
if (viewController == tabBarController.moreNavigationController)
{
tabBarController.moreNavigationController.delegate = self;
}
}
You have to "wire up" the delegate, either using code (in ViewDidLoad etc.) or in interface builder.
Look at this answer which explains how to connect a textView delegate (it's pretty much the same): https://stackoverflow.com/a/1785366/764575

pushViewController on UITableView

i have a TabBarController with 3 Views / Tabs...At one Tab i have an UITableView. Now i want if the user clicks on a cell switch to a detailview...i tried it already with this code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *nextController = [self.storyboard instantiateViewControllerWithIdentifier:#"detailView"];
[self.navigationController pushViewController:nextController animated:YES];
}
But it doen´s work...Any Ideas?!
You need to embed the table view controller in a navigation controller
If u want to use navigation controller do like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//for home tab.. u want to add navigation controller
YourTableViewController *objviewController = [[[YourTableViewController alloc] initWithNibName:#"YourTableViewController_iPhone" bundle:nil] autorelease];
UINavigationController *navCtrl = [[UINavigationController alloc] initRootViewController:objviewController];
//for tab2...
YourSecondViewController *objYourSecondViewController = [[[YourTableViewController alloc] initWithNibName:#"YourSecondViewController_iPhone" bundle:nil] autorelease];
//for tab3...
YourThirdViewController *objYourThirdViewController = [[[YourThirdViewController alloc] initWithNibName:#"YourThirdViewController_iPhone" bundle:nil] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navCtrl,objYourSecondViewController,objYourThirdViewController,nil];
self.window.rootViewController=self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
But u can add also add like if don't need navigation controller:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *nextController = [self.storyboard instantiateViewControllerWithIdentifier:#"detailView"];
[self.view addSubView:nextController];
}

how to show a tab bar controller after the login screen is launched?

This is a view based application.
in delegate.m file I have done like this to launch login screen initially:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[window addSubview:viewController.view];
[window makeKeyAndVisible];
LoginView *loginView=[[LoginView alloc]initWithNibName:#"LoginView" bundle:nil];
[window addSubview:loginView.view];
}
By adding the above code I have launched login screen sucessfully, but at the bottom of my login screen I can see a space left out.
How can the tab bar controller get launched after sucessful login?
i have creatd a method called login in my LoginView.m file:
-(void)login
{
if(login)
{
TabBarController *tabBarController = [[TabBarController alloc] initWithNibName:#"TabBarController" bundle:nil];
[self.view addSubView: aTabBarController.view];
}
[aTabBarController release];
Please help me out of this with the appropriate code.
you have to create on method in appDelegate like.. and In appDelegate.h you have to create an object like this
UITabBarController *Obj_tabbar;
and then in .m file,
-(void) switchToTabbarController
{
Obj_tabbar.delegate = self;
Obj_tabbar.selectedIndex = 0;
Tracking_HomeVC *obj = [[Tracking_HomeVC alloc]init];
[self tabBarController:Obj_tabbar didSelectViewController:obj];
[self.window addSubview:Obj_tabbar.view];
}
// At this point Tracking_HomeVC is the first view controller of the TabbarController. and it will be added on window.
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if([tabBarController selectedIndex] == 0)
{
//Write your code here to do with the first view controller object.
}
}
and then call it from your LoginView like..
-(void)LoginPressed
{
AppAppDelegate *delegate =(AppAppDelegate *) [[UIApplication sharedApplication] delegate];
[delegate switchToTabbarController];
}
Your login view (or it's controller if you have one which it looks like you don't) should tell the appDelegate to swap the RootViewController to be a taBarController. You do NOT want the loginview to be trying to add a tabBar as a child of itself.
One way of doing it is creating a tabbarcontroller like normal in your appdelegate and set it as rootviewcontroller:
TOTabBarController *tabBarController = [[TOTabBarController alloc] init];
UIViewController *vc1 = [[UIViewController alloc] initWithNibName:nil bundle:nil];
UIViewController *vc2 = [[UIViewController alloc] initWithNibName:nil bundle:nil];
UIViewController *vc3 = [[UIViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *vc2_nc = [[UINavigationController alloc] initWithRootViewController:vc2];
UINavigationController *vc3_nc = [[UINavigationController alloc] initWithRootViewController:vc3];
NSArray *viewControllers = [NSArray arrayWithObjects:vc1, vc2_nc, vc3_nc, nil];
[tabBarController setViewControllers:viewControllers];
//set tabbarcontroller as rootviewcontroller
[[self window] setRootViewController:tabBarController];
Then display the login screen modally (without animation) if the user is not logged in:
if (not logged in) {
UIViewController *lvc_nc = [[UIViewController alloc] init];
[[[self window] rootViewController] presentModalViewController:lvc_nc animated:NO];
}
Hope that helps!

navigate from one page to another in xcode

How can I navigate from one page to another page in xcode? remember without using the interface builder... I want the answer programmatically?
Pls be more precise if you want to get what you want.
If you are using view controllers within navigationcontroller you can make use of its pushViewController: or presentModalViewController:. Or if you just want to show another view you can just add the next view to existing view as subview.
Although your question is not much clear but still I would like to give a try...
You can use
UIViewController *yourViewController = [[YourViewControllerClass alloc] initWithNibName:#"<name of xib>" bundle:nil];
[self presentModalViewController:yourViewController animated:YES];
[yourViewController release];
In case the new view is also to be created programmatically, you can do that in the viewDidLoad method of YourViewControllerClass and change the initialization to
UIViewController *yourViewController = [[YourViewControllerClass alloc] init];
In YourViewController when you wish to come back to previous view on some button action you can use
[self dismissModalViewControllerAnimated:YES];
Another way that you can do is
UIViewController *yourViewController = [[YourViewControllerClass alloc] init];
[self addSubview:[yourViewController view]];
and to remove the view you can use
[self.view removeFromSuperview];
Hope this works for you, if yes please communicate....:)
//Appdelegate.m
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:self.viewController];
self.window.rootViewController = navigation;
[self.window makeKeyAndVisible];
return YES;
}
//In viewcontroller1.M
- (IBAction)GoToNext:(id)sender
{
ViewController2 *vc2 = [[ViewController2 alloc] init];
[self.navigationController pushViewController:vc2 animated:YES];
}

problem in UITable cell selection

hai ,
i have coded in UITableview in the method as follows.but when i touch the cell or row ,it wont
go to the next page(navigation did not work).have i to declare navigation conroller in other file.but i have coded app delegate in applicationdidfinishmethod for tab bar through dynamic.how can i link navigation?
the code:
UITableview;(TableViewController)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SubController *nextController = [[SubController alloc] init];
[self.navigationController pushViewController:nextController animated:YES];
[nextController release];
}
appdelegation:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
tabBarController = [[UITabBarController alloc] init];
tabBarController.navigationItem.title = #" News";
TableViewController *rtbfViewController = [[TableViewController alloc]
init];
rtbfViewController.tabBarItem.title = #"News";
InfoViewController *infoViewController = [[InfoViewController alloc]
initWithStyle:UITableViewStyleGrouped];
infoViewController.tabBarItem.title = #"Info";
tabBarController.viewControllers = [NSArray
arrayWithObjects:rtbfViewController,infoViewController,nil];
tabBarController.customizableViewControllers = [NSArray arrayWithObjects:nil];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
}
The problem is, that you don't have a UINavigationController, so self.navigationController in your TableViewController is nil (and thus messages sent to this property are ignored). You should modify your code in the app delegate as follows:
// [...] create tab bar view controller...
// create navigation controller with TableViewController instance as root view controller
TableViewController *rtbfViewController = [[TableViewController alloc] init];
rtbfViewController.tabBarItem.title = #"News";
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rtbfViewController];
// [...] create other view controllers
// NOTE: add the navigation controller to the tab bar controller, rather than the TableViewController
tabBarController.viewControllers = [NSArray arrayWithObjects:navController,infoViewController,nil];
tabBarController.customizableViewControllers = [NSArray arrayWithObjects:nil];
And don't forget to release your view controllers afterwards:
[rtbfViewController release];
[navController release];
[infoViewController release];