Hi i am working on an application which has a login form and another view called as Invitation. Now heres my problem in my Login view on the hit of Login button i am coming to the Invitation View with the help of the code which looks like this
-(void)buttonPress
{
Invitation *obj = [[Invitation alloc]init];
[self.navigationController pushViewController:obj animated:YES];
}
Now in the Invitation view what happens is that i want a tabbar to be displayed so i wrote a code which looks like this
objTabbar = [[UITabBar alloc]init];
HomeItem = [[UITabBarItem alloc]initWithTitle:#"Home" image:[UIImage imageNamed:#"house.png"] tag:0];
BluetoothItem = [[UITabBarItem alloc]initWithTitle:#"Bluetooth" image:[UIImage imageNamed:#"bluetooth.png"] tag:1];
NSArray *a = [[NSArray alloc]initWithObjects:HomeItem,BluetoothItem,nil];
objTabbar.items = a;
and in the LoadView method i did this
- (void)loadView {
[super loadView];
self.navigationItem.hidesBackButton = YES;
[self.view addSubview:objTabbar];
}
Now the code is building successfully but the problem is that the Tabbar is not getting displayed. I tried tabbarController and did this
tabbarController.view = objTabbar;
and added the tabbarController in the loadView method
[self.view addSubview:tabbarController.view];
But still no success
Please help me out and let me know where am i going wrong
Thank You
i believe the reason why you are not getting is because you are using the wrong code. Here are few mistakes i would like to point out.
replace objTabbar = [[UITabBar alloc]init]; with
objTabbar = [[UITabBarController alloc]init];
Replace objTabbar.items = a; with
[objTabbar setViewControllers:a];
Related
My First Question
DDMenuController(facebook split menu) Must be on RootviewController? it can not be on other viewController which we push on rootViewCotroller?
if answer is no then
Second Question
i am trying to make split viewController like facebook for that i am using this sample
https://github.com/devindoty/DDMenuController
now what i want to do is i dont want set DDMenuControl as rootviewcontroller in appdelegate in my rootcontrollers there are view buttons which push my all other ViewController
so what i want is from my rootViewController' Buttons i push another controller and then that view should get pushed and same time there should be DDMenuController too
so what will happen is on navigation bar there wont be back button there will be splitting screen button like facebook and from there i can go to another view controller
now let me tell you what i have achieved so far my rootViewController is getting displayed and then from there i push my other ViewController and on navigation bar splitting button is also getting displayed but its not working let me should you code to make this all clear
this is how i set my rootViewContoller in app delegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions
{
FirstPadViewController *mainController = [[FirstPadViewController alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:mainController];
self.window.rootViewController = navController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
so it get displayed with some buttons from where i can push my other viewController
this is how i push my other ViewController
- (IBAction)goToCamera:(id)sender {
AROverlayPadViewController *svController = [[AROverlayPadViewController alloc] init];
[self.navigationController pushViewController:svController animated:YES];
[svController release];
svController = nil;
}
so AROverlayPadViewController is getting pushed
and in AROverlayPadViewController's viewWillAppear this is what i do for achieving splitting screen like facebook
-(void)viewWillAppear:(BOOL)animated{
DDMenuController *rootController = [[DDMenuController alloc] initWithRootViewController:self];
LeftController *leftController = [[LeftController alloc] init];
rootController.leftViewController = leftController;
}
splitting button is getting displayed but when i press it is not working
now i really dont have any clue what to do any help will be highly appreciated
Answering the first question: actually it's a yes. This is how you do it, in the method that sends you to your nextScreen:
-(void) goToAnotherController {
OtherViewController *nextScreen = [OtherViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:nextScreen];
DDMenuController *menuController = (DDMenuController*)((AppDelegate*) [[UIApplication sharedApplication] delegate]).menuController;
[menuController setRootController:navController animated:YES];
}
Currently i am working in iPhone app, i have four screen like Login, A,B and c etc..
User enter the username and password field in login screen, then press login button
-(void)LoginButtonMethod
{
A *a = [[A alloc]init];
B *b = [[B alloc]init];
C *c = [[C alloc]init];
UINavigationController *navi1 = [[UINavigationController alloc] initWithRootViewController:a];
UINavigationController *navi2 = [[UINavigationController alloc] initWithRootViewController:b];
UINavigationController *navi3 = [[UINavigationController alloc] initWithRootViewController:c];
UITabBarController *TabBar = [[UITabBarController alloc] init];
TabBar.delegate = self;
TabBar.viewControllers = [NSArray arrayWithObjects:navi1, navi2, navi3, nil];
navi1.tabBarItem.title=#"A";
navi2.tabBarItem.title=#"B";
navi3.tabBarItem.title=#"C";
[self.navigationController pushViewController:TabBar animated:YES];
}
Then i have set navigationbar title for each class like A as facebook, b as yahoo, c as google.
Finally i run the application, tabbar title showing in A,B,C
Then i select 3rd tabbar item (C), at the time that tabar title change google.
i can't fix this, please help me.
Thanks in Advance
Apple in it's developer documentation states following:
"You never want to push a tab bar controller onto the navigation stack of a navigation controller. Doing so creates an unusual situation whereby the tab bar appears only while a specific view controller is at the top of the navigation stack. Tab bars are designed to be persistent, and so this transient approach can be confusing to users."
try presenting it
[self presentModalViewController:tabBar animated:YES];
You can push Tabbar to Controller By
Either
[self.navigationController pushViewController:tabBar animated:YES];
or
[self presentModalViewController:tabBar animated:YES];
Hope this will fix your problem
in this
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
Method of each view Controller put the following code..
self.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Comment" image:[UIImage imageNamed:#"Icon-AddComment.png"] tag:0];
self.navigationItem.title = #"Comment";
it Works
I am using a UIButton, on clicking it I want to display the contents that are present in my NSMutableArray in UITableView with the help of UIPopOverController i.e. I want a UITableView to pop up whose cells show the contents of my NSMutableArray.
I am using the following lines of code:
UITableViewController *table= [[UITableViewController alloc]init];
table.delegate = self;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:table];
self.popoverController = popover;
popoverController.delegate = self;
NSString *hDir = [NSHomeDirectory() stringByAppendingPathComponent:#"Documents"];
NSString *hFilePath = [hisDir stringByAppendingPathComponent:#"hhhh.txt"];
NSArray *array = [NSArray arrayWithContentsOfFile:hFilePath ];
NSMutableArray *kkkk = [[NSMutableArray alloc] init];
for (NSDictionary *dict in array) {
[kkkk addObjectsFromArray:[dict allKeys]];
}
table = [[UIImageView alloc] initWithFrame:[window bounds]];
// Set up the image view and add it to the view but make it hidden
[window addSubview:table];
table.hidden = YES;
[window makeKeyAndVisible];
I am unable to get the UITableView to pop up on the press of my UIButton. Can anyone help me to sort it out?
One way to show the UITableView in the UIPopOverController is by creating a new UIViewController class. And invoking it in initWithContentViewController method of UIPopOverController.
1. Create a new UIViewController or UITableViewController class. Create an instance of it.
2. Use the instance in the initWithContentViewController method of UIPopOverController.
3. Mention from where it should "pop"
For Example in your Button action :
-(IBAction)yourButtonAction:(id)sender
{
YourNewViewController*newVC=[[YourNewViewController alloc]init];
UIPopoverController*somePopOver=[[UIPopoverController alloc]initWithContentViewController:catergoryVC]; //Tell which view controller should be shown
[somePopOver setPopoverContentSize:CGSizeMake(200, 200)]; // set content size of popover
[somePopOver presentPopoverFromRect:yourButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; //From where it should "pop"
}
It seems you want to present it from a UIBarButtonItem so instead of presentPopoverFromRect use presentPopoverFromBarButtonItem
[somePopOver presentPopoverFromBarButtonItem:yourBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
If you want to display popover on press of button click, then first add your button in viewcontroller, display that view controller as follows:
In app delegate write code:
MyViewController *viewController = [[MyViewController alloc] init];
[self.window addSubView:viewController.view];
In MyViewController add button and provide target to that button displayPopup as follows:
-(void)displayPopup:(id)sender
{
UITableViewController *tblViewPopover = [[UITableViewController alloc] init];
tblViewPopover.tableView.delegate = self;
tblViewPopover.tableView.dataSource = self;
tblViewPopover.tableView.backgroundColor = [UIColor whiteColor];
tblViewPopover.tableView.separatorStyle= UITableViewCellSeparatorStyleSingleLine;
float theWidth = 280;
tblViewPopover.contentSizeForViewInPopover = CGSizeMake(theWidth,200);
if(m_popOvrController){
[m_popOvrController dismissPopoverAnimated:NO];
[m_popOvrController release];
m_popOvrController=nil;
}
m_popOvrController = [[UIPopoverController alloc] initWithContentViewController:tblViewPopover];
[tblViewPopover release];
[m_popOvrController presentPopoverFromRect:sender.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
}
and you can use tableview delegate methods to display data in tableview.
I think, UIPopoverViewController is initialized using UIViewController and here you are using UIView(UITableView).
Can you please try using UITableViewController instead?
Also, if things does not work according to plan when you create it using the code try using an XIB explicitely.
This should help.
I have a tabbarcontroller with three tabs/viewcontrollers.
When I first start my app, with my ActivityIndicator set to be visible and animated - courtesy of interface builder - it works fine.
However when I click a button an internet window opens to Facebook in order to get the user's permission.
Once the Facebook part is taken care it returns to my app but the ActivityIndicator is not longer animated - it is still visible though, just frozen.
If I switch to another tab/viewcontroller and then come back to the tab/viewcontroller with the ActivityIndicator everything works fine.
Is there a way to refresh my ViewController so that I don't have to programmatically make the ViewController switch back and forth? Or any other suggestions?
/* I searched the forums and I saw a similar question. It appeared that there was a broken connection. Therefore I'll include the code where I add the ViewController (i.e., "controller" to my tabbarcontroller). */
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
controller = [[DemoAppViewController alloc] init];
controller.view.frame = CGRectMake(0, 20, 320, 460);
controller.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"movieAppBackground.jpg"]];
MyTabBarViewController *vc2 = [[MyTabBarViewController alloc] init];
SecondViewController *vc3 = [[SecondViewController alloc] init];
controller.title = #"Intro Screen";
vc2.title = #"Explore";
vc3.title = #"Send a Pic";
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = [NSArray arrayWithObjects:controller, vc2, vc3, nil];
self.theTBC=tbc;
[controller release];
[vc2 release];
[vc3 release];
[tbc release];
[self.window addSubview:tbc.view];
[self.window makeKeyAndVisible];
return YES;
}
whereever u have used NIB file to show with viewcontrollers u have to create them with initwithname
Example
SecondViewController *r=[[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
like this change whereever u have used nib file to create instance,
i meaned for all custom viewcontrollers u have created with NIB file
How do I set the default selected UITabBarItem in an UITabBar that is within an UIView, not an UITabBarController?
Just to clarify, the UIView does implement the protocol and the didSelectItem method works. At run-time, the tabbar works and the tabbaritems selected when the user touches them. My problem is setting the default selected item.
If i use [myTabbar setSelectedItem] within the didSelectItem method it works. But outside of it, it doesn't (for example, in the viewDidLoad method of my UIView).
Thanks!
Thank you for your approatch, but I still have a problem that the didSelectedItem is not called when I select the item with setSelectedItem. Any Idea?
actually, I did use it a little bit different:
[tabbar setSelectedItem:[tabbar.items objectAtIndex:0]];
finally I solved it this way....
- (void)viewDidLoad
{
UITabBarItem *item = [myTabBar.items objectAtIndex:0];
[self.myTabBar setSelectedItem:item];
if(tab1Exam == nil){
self.tab1Exam = [[CurExam alloc] initWithNibName:#"CurExam" bundle:nil];
[self.view insertSubview:tab1Exam.view belowSubview:myTabBar];
if (currentViewController != nil)
[currentViewController.view removeFromSuperview];
currentViewController = tab1Exam;
}
}
You might want to post some sample code. I just ran a quick test in -viewDidLoad:
UITabBarItem *about = [[UITabBarItem alloc] initWithTitle:#"About" image:[UIImage imageNamed:#"About.png"] tag:0];
NSArray *tabBarItems = [[NSArray alloc] initWithObjects:about,nil];
[tabBar setItems:tabBarItems animated:NO];
[tabBar setSelectedItem:about];
[tabBarItems release];
[about release];
which worked fine, or at least worked as I expected.