I have a social app that requires login/sign-up. This is done with the ParseUI library that present a custom window for user validation.
When a user signs up, I want to display a CollectionView where users choose some preferences (each as a cell) and proceed to the app.
In the Sign-Up View Controller I have this:
- (void)signUpViewController:(PFSignUpViewController *)signUpController didSignUpUser:(PFUser *)user {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
ChooseLeagueCollectionViewController *clvc = [storyboard instantiateViewControllerWithIdentifier:#"ChooseLeagueViewController"];
[self dismissViewControllerAnimated:YES completion:NULL];
[self presentViewController:clvc animated:NO completion:NULL];
}
Do I need to alloc and init a flowLayout object even though it is already present in my storyboard?
In my storyboard I have a CollectionViewController containing one cell linked to a subclass of UICollectionViewCell with an ImageView and a Label. This storyboard file has as custom class 'ChooseLeagueViewController' which is a subclass of CollectionViewController, and is also data source and delegate.
In the .h file I have:
#interface ChooseLeagueCollectionViewController : UICollectionViewController <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
In the .m file I implement all the required methods that the datasource and delegate protocols require. In cellForItemAtIndexPath I populate the cell (subclass of CollectionviewCell), change the label text and text color, the image, and than return it.
Also I am not sure why I am asked to register my cell like below, even though my cell has a reusable identifier in the storyboard.
[self.collectionView registerClass:[LeagueCollectionViewCell class]forCellWithReuseIdentifier:#"leagueCell"];
Anyway when I run the app, after signing up, i am brought to a completly black screen but the battery. the app does not crash and all the 'data source' methods are called correctly.
I think that there is something wrong in the way I am trying to show this View.
Any guess on how I could improve my segue or what the mistake is?
thanks in advance
Simply alloc,init will give you blank controller with no view associated with it. You have to initialise it through storyboard like this, then you will not have to provide any custom init/alloc,
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
ChooseLeagueCollectionViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"yourViewControllerIdentifier"];
[self presentViewController:vc animated:NO completion:NULL];
You specify viewController identifier in storyboard by selecting your viewController and in identity Inspector in storyboard id. :)
Related
I am creating a custom keyboard that recreates the number and decimal keyboard, which is required for app submission. Currently I am using the method:
if ([self isOpenAccessGranted] == false) {
} else {
}
to check whether or not the user has allowed full access. When I try to load my storyboard file (Keyboard.storyboard) with the following method:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Keyboard" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"KeyboardViewController"];
[self presentViewController:vc animated:YES completion:nil];
The storyboard file just keeps refreshing in my custom keyboard view and functionality for the keyboard does not work. I labeled it with a storyboard id (KeyboardViewController) and checked the storyboardID button.
It is note worthing that when isOpenAccessGrantred is set to true, it loads a programmatically created UICollectionview Keyboard built using a collection frame. I have a suspicion this is what's causing it but not entirely sure.
Any guidance or advice would be greatly appreciated!
I figured it out.
If you are using a Storyboard file with Custom Keyboard make sure to edit your p-list to add the following:
NSExtensionMainStoryboard -> String -> Keyboard
and delete the following:
NSExtensionPrincipalClass -> KeyboardViewController
I have a use case where essentially I have a image in a customized table view cell. When the user selects the image we want to send them to a Profile page.
Normally, I'd do this by
- (IBAction)userClickedProfilePic:(id)sender {
ProfileViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"Profile"];
vc.postInfo = self.newsfeedData.newsFeedPosts[indexPath.row];
[[self navigationController] pushViewController:vc animated:YES];
}
But self != have a storyboard reference in this case since it's a UITableViewCell class. Is there a way to pop or push a new viewController from a tableviewcell action?
You have plenty of options. What I usually do is that I will create IBAction in viewcontroller which "contains" tableview with its cells. You can create IBOutlets or IBActions in all parents viewcontrollers through IB in a same way you would do it for cell..you might didn't know that.
But you want to click event on uiimageview which is not so straitforward. You have to do it programatically but it's not that hard just do something like this in cellForRowAtIndexPath and implement actionMethod:
UITapGestureRecognizer *actionMethod = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(actionMethod:)];
[cell.yourImageView addGestureRecognizer:actionMethod];
By the way instead of self.storyboard you can use this in case your storyboard is named Main.storyboard.
[UIStoryboard storyboardWithName:#"Main" bundle:nil]
I have a storyboard that handles all of my applications UI, apart from the header on each page which is handled by its own .xib file following this guide:
http://patientprogrammer.wordpress.com/2012/03/12/re-usable-subviews-in-ios/
Within my header .xib I have a button that I want to have when clicked load a view that is part of my story board.
I have tried:
- (IBAction)clicked:(id)sender {
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
someViewController *storyViewController = [mainStoryBoard instantiateViewControllerWithIdentifier:#"someViewController"];
[self.navigationController pushViewController:storyViewController animated:YES];
}
However as my class uses the interface UIView controller navigationController is not found, what can I do to launch a view within the story board from my UIView.
Or if there another interface I can use that will still let me have this as a subview.
what can I do to launch a view within the story board from my UIView
This is bad. A view is a view. Its purpose is to show something to the user, not controlling the app.
UIViewController is where you will need to do this. The navigationController is a property on this class, not on UIView. Read UIViewController class reference for more info.
So i'm using a storyboard AND a xib.
I use a tableview in my ViewController and it has a custom header as a xib file (the VC is the File Owner).
I want to present my new VC when swiping on the header, I added a swipe gesture to the xib using IB, but now i'm having problem presenting it.
Crash comes when i'm trying to instantiateViewControllerWithIdentifier. I made a property of my presented VC. And set the right Identifier "swipeRight".
- (IBAction)swipedRight:(id)sender {
NSLog(#"right");
if (_mpvc == nil) { //user those if only so the use wont push it twice and more
_mpvc = [self.storyboard instantiateViewControllerWithIdentifier:#"swipeRight"];
}
[self presentViewController:_mpvc animated:YES completion:nil];
}
The error:
Cannot find executable for CFBundle 0x9022120 </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk/System/Library/AccessibilityBundles/GeoServices.axbundle> (not loaded)
If you are inside a XIB file, how do you know which storyboard are you using? So first you have to instantiate storyboard which contains that viewController with specified identifier:
UIStoryboard *st = [UIStoryboard storyboardWithName:#"StoryboardName" bundle:nil];
After you have to instantiate viewController with this storyboard that you created:
UIViewController _mpvc = [st instantiateViewControllerWithIdentifier:#"swipeRight"];
Then finally you have to present the viewController:
[self presentViewController:_mpvc animated:YES completion:nil];
Hope it solves your problem!
hi I have a uicollectionview controller with two buttons ,when i click the first button it directly opens uitableview controller(with 2 button) and when i click the second button i want uicollectionview controller to show? how can i do this in storyboard?
i tried this code inside one button but its throwing one exception like "Nib file not found"
table *listview=[[table alloc]initWithNibName:#"listview" bundle:nil];
[self.navigationController pushViewController:listview animated:NO];
{list view is the uitableviewcontroller name ,i assigned this name on uitableviewcontroller title property in right panel of xcode}
"Nib file not found" error makes me reckon that you haven't spelled the .xib's name correctly.
Lets say you have your controller you want to push to.
TableViewController.h
TableViewController.m
And a corresponding xib thats linked with TableViewController.h. (view, IBOutlets, etc).
TableView.xib
Now in your main ViewController we push to TableViewController
TableViewController *controller = [[TableViewController alloc] initWithNibName:#"TableView" bundle:nil];
[self.navigationController pushViewController:controller animated:NO];
Hope this helps.
BooRanger
We can use Story board identifier for moving from uicollectionviewcontroller to uitableviewcontroller
table *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"list"];
[self presentViewController:vc animated:NO completion:nil];
Its working fine