Hey guys, I appear to have run into a problem. I have an application (View-based) that has a UITableView displayed on the bottom half of the screen, with the selection of a cell then bringing up a custom cell taking up the bottom of the screen. I have a "more info" button on the bottom right of this cell, and and when it is selected, I wish for it to open a new NIB file, however the only thing I can manage to do is remove the tableView from the screen..I am not sure of what to use before the "addSubview" because it is not self.view which I thought it would be.
- (void)moreInfoButton:(id)selector{
NSLog(#"Button Pressed");
MoreInfo *mivc = [[MoreInfo alloc] initWithNibName:#"MoreInfo" bundle:nil];
[self.tableview removeFromSuperview];
//[self.view addSubview:(UIView *)mivc];
[self.navigationController pushViewController:mivc animated:YES];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"List of Events" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
[mivc release];
}
Also, the (UIView *) doesn't do the trick either. Any suggestions?
P.S. The UITableView does not use a navigationController at all, it is just the table, would this be the problem?
Also, what if I chose to just push a new view, and not use the navigationViewController for this view, is this possible?
I can't answer your navigation controller question without seeing more of your program. To answer your other question, without using a navigation controller you can just add a new view with:
newViewVC = [[NewViewVC alloc]initWithNibName:#"NewViewVC" bundle:nil];
[self.view addSubview:newViewVC.view];
Typically newViewVC is declared in your .h so you can release it later.
I have found an easy way: pushing it as a modal.
- (void)moreInfoButton:(id)selector{
NSLog(#"Button Pressed");
MoreInfo *mi= [[MoreInfo alloc] initWithNibName:#"MoreInfo" bundle:nil];
[self presentModalViewController:mi animated:YES];
}
All that is needed is a back button in the new nib file.
Related
ABCViewController *loginPopUp = [[ABCViewController alloc]initWithNibName:#"ABCViewController" bundle:Nil];
loginPopUp.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController: loginPopUp animated:NO completion:nil];
while click on textfield, keyboard is not raising and screen hangs
we found a solution for above issue we used UIModalPageFormSheet instead of UIModalPresentationFormSheet. UIModalPageFormSheet is supporting both iOS8 and iOS7.
I am using the following code:
CCMenuItemFont *controllerItem = [CCMenuItemFont itemFromString:#"Analog" target:self selector:#selector(controllerToggle)];
CCMenu *controllerTypeMenu = [CCMenu menuWithItems:controllerItem, nil];
[controllerTypeMenu alignItemsVerticallyWithPadding:30.0f];
controllerTypeMenu.position = CGPointMake(160.0f, 240.0f);
[self addChild:controllerTypeMenu z:0 tag:ControllerMenu];
}
-(void) controllerToggle
{
CCMenuItemFont *controllerItem = [self getChildByTag:888];
NSString * text = [NSString stringWithFormat: #"switching.. %f", CCRANDOM_0_1()];
[controllerItem setString:text];
}
In controllerToggle I would like to access to controllerItem and change the String to another value. Is this possible? I checked and CCMenu adds as child the CCMenuItems based the array order. But that's not an elegant solution. For the same reason I cannot add the CCMenuItem to the Scene as it will give me "child already added error". So I feel I should write my own "switch" button but I wonder if there is already something out there..
Any help?? Thanks!
you can declare needed menu item as class member. In this way you will be able to get access to it whenever you want
There is already CCMenuItemToogle which is used to switching the title or image of any menuitem on click event.Instead of taking CCMenuItem you can use CCMenuItemToggle..
Here is a sample code
CCmenuItemToggle *cam=[CCMenuItemToggle itemWithTarget:self selector:#selector(openCameraController) items:cameraOn,cameraOff, nil];
where cameraOn and cameraOff are two simple CCMenuItemImage which is added in CCMenuItemToggle and further this CCmenuItemToggle is added in a menu.
Now on every click of CCMenuItemToggle there will be a cameraOn and cameraOff state for same menuitem.
Hope this will help...
I have called a the "AppearanceWhenContainedIn" method in my AppDelegate to set the the title color of all of my buttons in Navigation Controller classes. The call is as follows:
[[UIButton appearanceWhenContainedIn:[UINavigationController class],nil] setTitleColor
[UIColor colorWithRed:0 green:0.475 blue:0.227 alpha:1] forState:UIControlStateNormal];
This works the way I want it to, however, there is one UIView where I have a button in a toolbar that I want to keep the title text of the button white (not change the color). The button and toolbar were added in my .xib file and I have the button attached to an IBAction that dismisses the modal view controller (it's an "About" view).
How would I change the text color of this specific button, or make an exception in my appearanceWhenContainedIn call?
Thank you very much for your help.
I guess in my case, because the button was in a toolbar, I used a customizeAppearance method in my AppDelegate to change the appearance of all button items in toolbars. The code was:
[[UIBarButtonItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],
UITextAttributeTextColor,
[UIColor whiteColor],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"ArialMT" size:0.0],
UITextAttributeFont,
nil]
I am trying to add menu to a layer in cocos2d but it just does not appear. Here's the code which is written in init method of a layer
CCMenuItem *aButton = [CCMenuItemImage itemFromNormalImage:#"btnImg.png" selectedImage:#"btnImgSel.png" target:self selector:#selector(buttonPressed:)];
aButton.position = ccp(60.0,30.0);
CCMenu *aMenu = [CCMenu menuWithItems:aButton, nil];
aMenu.position = ccp(500.0,20);
[self addChild:aMenu];
Nothing is overlapping the position i specified for menu. Is anything wrong in the code?
Try like these:-
CCLayer *menuLayer1 = [[[CCLayer alloc] init]autorelease];
[self addChild:menuLayer1];
CCMenuItemImage *startButton1 = [CCMenuItemImage
itemFromNormalImage:#"Play.png"
selectedImage:#"Play.png"
target:self
selector:#selector(Play:)];
CCMenu *menu1 = [CCMenu menuWithItems: startButton1,nil];
menu1.position = ccp(157,157 );
[menu1 alignItemsVertically ];
[menuLayer1 addChild: menu1];
For those who are facing an irritating situation where the code is right but menu items are not showing then check the image file. I was using .png images and they were refusing to be displayed. There was something internally wrong with the file, so I replaced that file and it solved the problem :)
Is the iPad your target platform? If so the "menu" should appear at the bottom of the screen. To display the Menu on iPhone adjust the "a.Menu.position" to anything lower than 480 in the first attribute of ccp
I am building an ap in which I need to remove the present view from the superView and load another one. But the new loaded view shifts upward. Also when the firstView is again loaded, it loads perfectly.
Could anyone possible suggest something to get rid of this issue.
Following is the method I am using to flip the view to secondView
-(void) flipToBack
{
CreateMessageViewController *oSecondView = [[CreateMessageViewController alloc] initWithNibName:#"CreateMessageViewController" bundle:nil];
[self setMsgViewController:oSecondView];
[oSecondView release];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.8];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];
[viewController.view removeFromSuperview];
[tabBarController.view removeFromSuperview];
[self.window addSubview:[msgViewController view]];
[UIView commitAnimations];
}
Thanks in advance!!
Looking forward to your kind responses.
thanks
There is not much I can tell without looking at the big picture. Check the frames in the IB to see if they are correctly set.
Is this code from your appDelegate? Does viewController have a toolbar shown on his view? Maybe your view is shifted the exact pixels your toolbar height is?
Got it.
It's happening due to the IB settings. So in IB your viewController has a statusBar and your view has a height of 460 (for iPhone) not 480. The 20 points are the statusBar height. When transitioning to the second view, its rect is {0,0,320,460} so the view is positioned behind the application's statusBar and you are missing 20 points from the bottom.
To get around this you need to:
Go into IB and set the CreateMessageViewController's statusBar to Unspecified.
Go into the view size section and set the view's height to 480 (for iPhone).
Now your CreateMessageViewController's view will show properly.
After long time playing around with the code and IB, I found the bug. It was corrected as
Open the mainWindow.xib and add the UIViewController Object from the Library. Change its class to your Class that handles the specified viewController and then comes the click. Go to the properties section of the Attribute Inspector and set the respective Nib Name for the Controller and now save and exit the IB.
And the code changes to
-(void) flipToBack
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.8];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES];
[viewController.view removeFromSuperview];
[tabBarController.view removeFromSuperview];
[self.window addSubview:[msgViewController view]];
[UIView commitAnimations];
}
Thanks to all who responded!!