Hi i currently have a navigation based app with a navigation controller, within the app numerous views and pushed and popped back displaying different xibs, what I would like to do is display a button fixed on the screen in the bottom right of the screen, which when tapped will take the user to a help xib,
However at the moment the button is being animated and moved into place every time I push a or pop a view, I would like the button not to move and stay on top of the views when they are being pushed and popped.
Wondering if anyone can help me, thanks, Sami.
Create a UIView Class in that create UIButton And create object of that view in all the viewcontrollers,and add it to the self.view.
using this in appdelegate will help u to show button in all the screen.
if u need handle this button, import viewcontrollerAppdelegate.h to the view controller. and use
UIAppDelegate.SettingButton.hidden=True;
or like this any. just try
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
settingButton = [UIButton buttonWithType:UIButtonTypeCustom];
[settingButton addTarget:self action:#selector(settingButtonPressed:)forControlEvents:UIControlEventTouchDown];
UIImage *buttonImage = [UIImage imageNamed:#"icon-lb.png"];
[settingButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
[settingButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
settingButton.frame = CGRectMake(265, 17, 40, 45);
settingButton.hidden=TRUE;
[self.window addSubview:settingButton];
[self.window makeKeyAndVisible];
return YES;
}
- (void)settingButtonPressed:(id) sender {
[[NSNotificationCenter defaultCenter] postNotificationName:#"settingButtonPressed" object:nil];
setting *obj = [[setting alloc] initWithNibName:#"setting" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:obj];
navController.navigationBar.tintColor=[UIColor blackColor];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[self.window addSubview:navController.view];
[navController.view setFrame:CGRectMake(0,480,320,480)];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:navController.view cache:YES];
[navController.view setFrame:CGRectMake(0,0,320,480)];
[UIView commitAnimations];
}
Related
I have a UIViewController its my main view controller. When the app starting that main viewcontroller is loading. Then there is a bar button. When I click on that, another view controller loding like this.
LoginViewController *viewController = [[LoginViewController alloc]
initWithNibName:#"LoginViewController" bundle:nil];
viewController.mainViewController = self ;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
[navController setModalPresentationStyle:UIModalPresentationFormSheet];
navController.navigationBar.tintColor = [UIColor blackColor];
[self presentModalViewController:navController animated:YES];
In that new view controller I am doing some tasks and when click the close button, the results should be loaded in on the parent view controller.How can I do this. In parent view controller ViewDidAppear also not calling when I just close the top view controller. How can I do this? Please help me.
Thanks
First of all the line of code
[self presentModalViewController:navController animated:YES];
is deprecated and its been a long time, I don't know why are you still using it.
// Use below code instead
[self presentViewController:viewController animated:YES completion:nil];
Also you need to use protocols and delegates to pass any object to parent viewcontroller while you are dismissing the other viewcontroller.
If you can show up some code we might be able to figure out that why your viewDidAppear is not calling.
I've got a custom tab bar that I created using this link: https://github.com/jain-mohit/CustomTabBar. Now, I want to open a view modally after pressing a button. The opened view must be transparent, meaning I can see the view beneath it. The modal view also must a navigation bar so I can put a "Cancel" button to dismiss it. I've tried it like this:
DetailsViewController *detailViewController = [[DetailsViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:detailViewController];
nav.modalPresentationStyle = UIModalPresentationCurrentContext;
nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
detailViewController.view.backgroundColor = [UIColor greenColor];
detailViewController.view.alpha = 0.5f;
[self presentViewController:nav animated:YES completion:nil];
This method quite works but when opening, the view doesn't transition from bottom to top. And I also got this error:
Presenting view controllers on detached view controllers is discouraged <UINavigationController: 0x8f52280>
So, I'm looking for another way to do this. Hopefully someone can help. This method should work for iOS6, 7 and 8. Also I'm not using storyboard to do this.
Thank You.
Try to use UIWindow, instead of presenting a new ViewController:
UIWindow *w = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
w.windowLevel = UIWindowLevelAlert;
w.autoresizesSubviews = NO;
w.clipsToBounds = YES;
w.hidden = NO;
[w addSubview:detailViewController];
In this case background of your new ViewController will be transparent, but you can't use UINavigationController here...
I'm trying to add a menuViewController on top of my navigationBar and rootView.
menuView = [[MenuViewController alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width*0.4, self.view.frame.size.height)];
UIViewController *rootViewController = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
rootViewController.modalPresentationStyle = UIModalPresentationFullScreen;
[[self navigationController] presentViewController:menuView animated:YES completion:nil];
That is my code, however the view goes black after the animation.
Any ideas?
Try using UIModalPresentationCurrentContext instead of UIModalPresentationFullScreen.
I'm presenting an UIViewController using a custom transition implementation:
JWModalController *modal = [[JWModalController alloc] init];
CGRect originalFrame = [[self view] convertRect:[[modal view] frame] toView:nil];
[[modal view] setFrame:CGRectZero];
[[self view] addSubview:[modal view]];
[self addChildViewController:modal];
[modal didMoveToParentViewController:self];
[UIView animateWithDuration:0.6 animations:^{
[[modal view] setFrame:originalFrame];
}];
This works great and i'm quite happy with the result.
BUT: When presenting a viewController the regular way ([self presentViewController:modal completion:nil];), the keyboard dismisses if a textfield is first responder.
When using my way, the keyboard does not dismiss.
Sure, I could easily keep track of the first responders or save the textField and call -resignFirstResponder manually... But I really want to know how to do it the right way.
I have created a custom cell with buttons.
the buttons should present a modalViewController, one for the email and another for a webView.
I have also created a delegate to get a callback from the class.
so in the cell class:
_delegateAction = [[HistoryVC alloc] init];
_delegateAction.delegate = self;
[_delegateAction openData:_data Type:_title.text]; //start process
The class that the table is on is a UIviewController that have a table view. the (with the custome cells that are another class inherit from UiTableViewCell.
if you need meed information just tell me.
in the UIviewController I am trying to present a modal view as follow:
-(void) openData: (NSString *)data Type:(NSString*)type
{
QRWebView * webView = [[QRWebView alloc] init];
webView.url = data;
[self presentModalViewController: webView animated:YES];
}
The modalview doesn't show. I know that I'm doing something wrong, but what is it?
Thanks in advance.
You have created a new view controller with _delegateAction = [[HistoryVC alloc] init]; but you haven't made it part of the controller hierarchy by presenting it in any way.
When you call [self presentModalViewController: webView animated:YES];, your self is the new controller and, since it's not in the hierarchy, it's not capable of presenting another controller.
I have managed to fix it by implementing the PresentModalView.
What I did is to create a showModal and DismissModal in the AppDelegate class.
Those method add to the Window the view I wanted by adding it as:
[Window addsubview TheView];
and for the Dismiss is removeFromSuperview.
I implemented an animation to fake the modalView animation.
to get to those methods I have used the shareApplication.
and it's works.