Hi I want implement this animation effect(using storyboard), when user click a tab bar(say 2nd tab bar item), it displays the corresponding view like a modal view(display upwards to the screen)
My current method is delegate tab bar controller to tab bar and rewrite
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
NSLog(#"rawr");
NSLog(#"inside tab bar did select, index is %d", self.selectedIndex);
if (item == [self.tabBar.items objectAtIndex:1]) {
//item.title = #"modal view";
NSLog(#"going to promote as modal view");
CBTab2ViewController* modalViewController = [[CBTab2ViewController alloc] init];
[self presentViewController:modalViewController animated:YES completion:nil];
}
}
The problem is, the view displayed is a black screen, any idea how to implement it correctly?
my source code can be found a link below:
https://www.dropbox.com/s/6rd6ek59xf0yiq4/testtabbar.zip
Change the lines :
CBTab2ViewController* modalViewController = [[CBTab2ViewController alloc] init];
[self presentViewController:modalViewController animated:YES completion:nil];
To this one (incase your storyboard name is "MainStoryBoard"):
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard"
bundle: nil];
CBTab2ViewController * modalViewController = (MyViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: #"CBTab2ViewController"];
[self presentViewController:modalViewController animated:YES completion:nil];
Related
I want to go to a view controller when the button "Cancel" is pressed. I tried using this method but when I click 'Cancel", it just displays a black screen. I am a beginner at IOS.
-(void) cancelButtonPressed {
homeView = (HomeViewController *)[[UIViewController alloc]init];
[self presentViewController:homeView animated:YES completion:nil];
}
EDITED FOR COMMENTS:
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]initWithTitle:#"Cancel" style:UIBarButtonItemStylePlain target:self action:#selector(cancelButtonPressed)];
self.navigationItem.leftBarButtonItem = cancelButton;
Try doing this:
HomeViewController *homeView = [[HomeViewController alloc]init];
[self presentViewController:homeView animated:YES completion:nil];
Also note that black is the default colour of the window. If you don't have any view controller named HomeViewController, and you present it, by default it will be visible as black colour to the user.
To Avoid this, you need to set the View for the newly presented view controller, which you can access by homeView.view
If you are using storyboard, then use storyboard ID:
HomeViewController *homeView = [self.storyboard instantiateViewControllerWithIdentifier:#"HomeViewController"];
[self presentViewController:homeView animated:YES completion:nil];
In my app after pressing the login button in my loginViewController, it push to front viewController of my SWRevealViewController. In my RearViewController I have the sign out button. When I press it it should pop to the back viewController again (LoginViewController). But even though I set the button click event like this it doesnt navigate to the loginViewController.
-(void)signOutClick :(id)sender
{
[self performSelectorInBackground:#selector(moveToLoginView) withObject:nil];
}
-(void)moveToLoginView
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
But when I swipe the view it gose to the back view.I want to disable that swipe feature to the back view. And I want to go to the back view when click on the sign out button in my RearViewController. How can I do that? Please help me.
Thanks
I am not sure but instead of using
[self.navigationController popToRootViewControllerAnimated:YES];
try using,
[self.navigationController popViewControllerAnimated:YES];
And to stop swipe gesture you can use code like,
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.revealViewController.panGestureRecognizer.enabled = NO;
}
You need to reset the top view controller if you want to perform these kind of actions off of a click. E.g.
get an instance of the ECSlidingViewController
ECSlidingViewController *slidingController = self.slidingViewController;
get the view controller you wish to be on the top
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:#"mainViewController"];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
set the topViewController property
slidingController.topViewController = nc;
[slidingController resetTopViewAnimated:NO];
I am trying to show navigation controller when i present PresentViewController for navigate a screen. I solved this problem, but i faced another problem. Problem is when i push to a screen that time back button is visible on next screen with navigation controller. But when i am trying to PresentViewController, that time navigation bar is visible but not back button.
Here is my code:
- (IBAction)clickMeAction:(id)sender
{
ViewController1 *viewcontrol = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewID"];
//[self.navigationController pushViewController:viewcontrol animated:YES]; // this is for push to viewcontroller
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewcontrol];
[self presentViewController:navigationController animated:YES completion:nil]; // This is for modalviewcontroller
}
Here is my output:
with push:
with modal:
Please help me.
Method 1:
[navigationController presentViewController:navigationController animated:YES completion:^{
[navigationController setNavigationBarHidden:YES animated:NO];
}];
Method 2: in presentViewController
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
}
My app it's embedded in a tab bar controller, but I'm using a nib in which I'm doing some operation.
At the end of this operation I've to pop to a view controller in my tab bar controller. I tried to use this code (suggested by an another user on here):
[self.tabBarController setSelectedIndex:<#(NSUInteger)#>];
[self.navigationController popToRootViewControllerAnimated:NO];
but it doesn't do anything. I guessed i should use this instructions:
[self dismissViewControllerAnimated:NO completion:nil];
but I've to put something in the completion, I don't know how to do that, can you help me?
Update:
I will show you my storyboard so you can understand what I'm trying to explain:
also in "Product View Controller", when I press on a button (I design the button by code) it shows me this file XIB:
In this view there's a button (usually it's hidden), when I press on this button it will add the product I'm looking to a remote cart. After the adding this product to the remote cart, I will pop to the "Carriage View Controller". When I pop to the "Carriage View Controller" I should pass them some data of my cart.
So my app has this tab view:
Home View Controller: the main view controller, loaded when the app is started
Category View Controller: it's a table view controller in which I'm displaying the category of products in my store
Carriage View Controller: a controller in which I will display the data of my cart
Info View Controller: a controller in which I display information about the app
From the "Category View Controller" with a segue I pop a View Controller in which I display by a custom view the products. When I press on one of this products it calls a the xib file I posted before file in which there are the details of the product selected before.
I hope you understand better what I'm trying to do.
CODE:
Here's the code to display the xib I posted:
- (void)collectionView:(PSCollectionView *)collectionView didSelectCell:(PSCollectionViewCell *)cell atIndex:(NSInteger)index {
int productID = (int)index;
productID = productID + 1;
if (IS_IPHONE_5) {
ProductScannedViewController *productScannedVC = [[ProductScannedViewController alloc]initWithNibName:#"ProductScannedViewControllerRetina4" bundle:nil];
productScannedVC.idProductScanned = [NSString stringWithFormat:#"%d", productID];
[productScannedVC setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:productScannedVC animated:YES completion:nil];
} else {
ProductScannedViewController *productScannedVC = [[ProductScannedViewController alloc]initWithNibName:#"ProductScannedViewController" bundle:nil];
productScannedVC.idProductScanned = [NSString stringWithFormat:#"%d", productID];
[productScannedVC setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:productScannedVC animated:YES completion:nil];
}
}
[self dismissViewControllerAnimated:YES completion:^{
// completion code here
}];
You can only use the popToRootViewControllerAnimated method if the view controller is part of that navigation controller's navigation stack.
If you are presenting the view controller like this
TestViewController * vc = [[TestViewController alloc] init];
[self presentViewController:vc animated:YES completion:^{
}];
And want to do the tab navigation inside I suggest injecting the tab bar as a weak property
TestViewController * vc = [[TestViewController alloc] init];
[vc setTabController:self.tabBarController];
[self presentViewController:vc animated:YES completion:^{
}];
Inside the TestViewController where you want to do the navigation:
[self dismissViewControllerAnimated:YES completion:^{
[tabController setSelectedIndex:0];
}];
I tested this code.
I have 6 view controllers when my app starts. It's like an image gallery. When a user pushes for example the button on the third view, he/she should gets to the third view in the tab bar.
I use this code to launch the view controllers on the top of the tab bar controller:
- (void)viewDidAppear:(BOOL)animated {
static BOOL first = YES;
if (first) {
UIViewController *popup = [[Home1ViewController alloc] initWithNibName:#"Home1ViewController" bundle:nil];
[self presentViewController:popup animated:NO completion:nil];
first = NO;
}
}
By using this code to dismiss this new view, I'm just coming to the specific view, but not my tab-bar page...
-(IBAction)dismissView {
TabBarPage3 *screen = [[ TabBarPage3 alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:screen animated:YES];
}
Please help me with this!
Thanks
This is the code for change view on TabBar
[((UITabBarController *)(self.parentViewController))setSelectedIndex:index];
Sample Project of UITabbar