UIToolbar as Subview into another UIViewController is not clickable - iphone

I am creating an app with multiple UIViewController, they have common menu and toolbar in header. i have created a uiviewcontroller with nib for top UIToolBar with some UIToolBarButtons. I am calling in another UIViewController, my problem is this that UIToolBar is displaying but any of UIToolbar button is not clickable now, they are not working. so it only showing the view which is not working at all.

Please see UIView UserInterfaceEnabled or not. if not then just write below code in your viewdidload
self.view.userInteractionEnabled = YES;
OR also try this
[self.view bringSubviewToFront:youtoolbar];

just try this code something skip you from your code
[yourBarButton setTarget:self];
[yourBarButton setAction:#selector(yourBtnClicked:)];
[yourToolBar setUserInteractionEnabled:YES];
[self.view setUserInteractionEnabled:YES];
[self.view bringSubviewToFront:yourToolBar];
UPDATE:
For use this UIToolBar to every UIViewController, just add it in window and set method in AppDelegate class also...
hope this help you...

Try this.. You remove your toolbar in viewWillAppear and add it again like
(void)viewWillAppear:(BOOL)animated
{
[yourtoolbar_reference removeFromSuperview];
[self.view addSubview:yourtoolbar_reference];
}

Related

Add a subview to MasterView of UISplitViewController

I need to add a subview to left part of UIViewController, which shows the user that there is something near the left part of screen, when masterview is hidden(in portrait orientation). And this view must move with left part of UISplitView. Something like the view with arrow in these two images. (Sorry for the russian interface)
http://s2.uploads.ru/8EHJI.png
http://s2.uploads.ru/NhEam.png
But my problem is that when I try to add such a view, it clips to bounds of masterview and is not visible when masterview is hidden. I think, I'm doing it wrong and there is an easy way to do this.
Update: I've tried to make some hack like:
-(void) clipToBoundsRecursive:(UIView *)someView
{
NSLog(#"%#", someView);
someView.clipsToBounds = NO;
for (UIView *v in someView.subviews)
{
[self clipToBoundsRecursive:v];
}
}
and send it to view of splitviewcontroller.
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
[self clipToBoundsRecursive:splitViewController.view];
It takes effect at first time (subviews outside the masterview's bounds shows, but after first show/hide animation they disappears and don't appear even if I call this method again)
You can add the view directly to the window's view, though you will have to manually manage its position depending on when the device rotates. Views added to the window.view will appear above the rootViewController.view.
I have described here a simple Logic for you: (how to add a UIView in Window and call it from your master or detail view )
Create UIView in #import "AppDelegate.h" ,
- (void) CreateViewInWindow
{
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 780)];// set as u wish
myView.backgroundColor = [UIColor redColor];
// I have added myView to the Window with a specific animation , your can give animation as you like. :)
[UIView transitionWithView:self.window duration:0.5
options:UIViewAnimationOptionTransitionCrossDissolve // change to whatever animation you like
animations:^ { [self.window addSubview:myView]; }
completion:nil];
}
Here create a simple UIButton in the DetailViewController.m file (You can put the code in either of the files, DetailViewController.m OR MasterViewController.m)
UIButton *btnShowView = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnShowView addTarget:self action:#selector(btnShowViewTapped:) forControlEvents:UIControlEventTouchUpInside];
btnShowView.frame = CGRectMake(20, 30, 174, 35);
//[btnLoginInner setBackgroundImage:[UIImage imageNamed:#"LoginBut.png"] forState:UIControlStateNormal];
[self.view addSubview:btnShowView];
In button tapped method, write code for calling UIView from AppDelegate, and also don't forget to add #import "AppDelegate.h" in DetailViewController.m,
-(void)btnShowViewTapped:(UIButton *) Sender
{
AppDelegate *del = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[del performSelector:#selector(CreateViewInWindow) withObject:nil afterDelay:0];
}
Above code is a simple logic for your problem, It might be helpful for you.
Sounds to me like your app could benefit from PKRevealController.
Try with deselecting auto layout option in identity and type pan if you are using nib otherwise set autoresizing mask to view that currently clipping. I believe it will solve the issue

iPhone - Remove view and NavigationController

I have a ViewController which creates a NavigationController and puts a UIView in it.
nvcontrol =[[UINavigationController alloc] initWithRootViewController:menuView];
...
UIView *parent = self.view.superview;
[parent addSubview:nvcontrol.view];
I need to close the view (incl. the NavController) from within the child-viewcontroller.
The following snippet I tried, only closes the view inside the NavController, not the NavController itself. This ends up showing the blue head with a white space below.
[self.view removeFromSuperview];
What could solve this?
I have not tried this but I think something like this should work:
[self.navigationController.view removeFromSuperview];
#traingle_man Are you sure view is a property of uinavigation controller?
If I understand your question correct, this may help
[nvcontrol.view removeFromSuperview];

Removing a UIView

So I have a view controller called MainViewController with a button which when I press this code is called:
NewViewController *newViewController;
newViewController = [[NewViewController alloc] initWithNibName:#"NewView" bundle:nil];
[self.navigationController.view addSubview:newViewController.view];
[newViewController release];
This brings in the new view which works great. However, how can I remove this view from a button within it? In an application I wrote a while ago I simply created a method in MainViewController called RemoveView and within the XIB file for NewViewController I selected FirstResponder and then RemoveView for the button. This works but I can not replicate it in my new project and don't really understand how it works anyway!
It's not the remove view code I'm looking for, more the way of getting the method to call from another class.
If anyone could help me that would be great! :)
Thanks
Drawing the line in Interface Builder does the same thing as calling
[theButton addTarget:theController action:#selector(theAction) forControlEvents:UIControlEventTouchUpInside];
theAction needs to be a method that is defined with a type of IBAction.
For your situation, in your NewViewController.h, declare
- (IBAction)removeView;
Then in NewViewController.m:
- (void)removeView
{
[self.view removeFromSuperview];
}
In your newView.xib file, you should be able to drag a line from the UIButton that you've drawn to your File's Owner, and select the removeView action.

UIView remove itself from UIScrollView

Following Scenario:
I have a = UIViewController A that contains a UIScrollView
I have a second UIViewController "B" (amongst other things it contains a button)
and add it to the ScrollView of A
myView *mView = [[myView alloc] init];
[myScrollView addSubview:mView.view];
Is there a way that once the button is pressed that it(view) removes itself from the scrollview?
I thought in the direction of setting the delegate of mView to "A" ?! But not sure how that should work in detail....
Any suggestions?
Thanks!
In the controller, you can call:
[self.view removeFromSuperview];
If you have a reference to view you can do the following:
[view removeFromSuperview];
If you don't have a reference, please post more code and I can modify my answer for you.

UIView disappears after modalViewController is removed from superview

In my app I have a tabBarController and in it a navigationController. One of my view controllers is a TableViewController and under the navigationBar i added a uiView as a subview to the view like this:
rectangleInfo = [[UIView alloc] initWithFrame:CGRectMake(0,0,[[UIScreen mainScreen] applicationFrame].size.width,26)]; rectangleInfo.autoresizingMask = (UIViewAutoresizingFlexibleWidth); rectangleInfo.backgroundColor = [UIColor darkGrayColor]; [self.view addSubview: rectangleInfo];
when I click on a cell in the tableView I push an UIViewController like this:
[feedViewController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[[self navigationController] presentModalViewController:feedViewController animated:YES];
After i pop the modal view for a couple of times with it from the tableViewNavigationController disappears the rectangleInfo UIView.
I pop my modalview like this:
[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
[self setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self dismissModalViewControllerAnimated:YES];
any idea why that subview (rectangleInfo) of the tableViewController dissapears after i remove the modal view from the superview?
thank you in advance.
I'm curious as to what you are trying to do with your rectangleInfo view? By the size of it, it looks like you are trying to mimic the status bar. Why? You can just hide the status bar if you want.
Another thing you can try is to create the UIView visually in Interface Builder. Don't actually add it to your main view, but create it as a separate UIView in the XIB with the appropriate size, etc. Then create an outlet for it in Xcode and connect it. Next, add it as a subview in code when your view controller loads. See if that makes a difference. This is especially strange since you say it only disappears after popping it several times. Do you get the same problem if you push and pop the non-modal way, e.g.:
[[self navigationController] pushViewController:feedViewController animated:YES];
[[self navigationController] popViewControllerAnimated:YES];
i solved the problem by implementing correctly the viewDidLoad and viewDidUnload methods for creating and releasing my subviews.