Im new to storyboard. Im trying to create a tableview with static cells (1 section with 2 rows). Now i need to go to different views on taping the rows.
How can i connect the view in Interface builder??
This method is not required as im not passing any data to the next view.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSLog(#"%#",segue.identifier);
}
I need to show static views on tapping the row of the table.
In interface builder im not able to create more than 1 segue for a section.
Open your story board in separate window so that your source code is also seen on display;
Open your *.h file (perhaps that one your main view controller is declared);
In interface builder, drag the event you want to use to your *.h file. xcode will draw something like a placeholder in the place you drag it and when you drop it, it will generate IBaction method for you. Just implement it (using segues or something else) and here you have it.
prepareForSegue is different thing. You may use segues too (think of segue as about descriptor of your controller-to-controller move) but it is a different workflow. There is tons of documentation on this.
Related
I have an app that represents a folder structure. I have a UITableViewController for the folders and files listing, and a UIViewController for the Documents.
I want to be able to recursively navigate through the folder structure, so I want to reuse the Folder UITableView multiple times while I let the user drill down a folder structure.
Is there a way to draw a segue from the UITableViewController to self so when I select a folder I present another instance of the view, but with the content of the subfolder?
I did this in previous versions of Xcode, but I cannot figure this out on Xcode 9.
You can use Storyboard Reference and Storyboard ID of ViewController in Interface Builder
Screenshot
Yes you can do it. Add a hidden button in view controller and drag & drop segue self view controller.
I've never created a segue link to the same view controller, but based on Halil's answer above, it sounds like it's possible.
Rather than messing with hidden buttons, though, why don't you give your scene a storyboard identifier, and then instantiate and push/present your view controller through code? You could put your logic in the table view's tableView(_:didSelectRowAt:) method.
I need to navigate inside folders and files in directory (from server). The problem is that I don't know the number of folders so it's not possible to use performSegueWithIdentifier statically. How can I use navigation controller with dynamically number of view controllers in swift? I want to "push" a new view controller every time a user tap on a folder in order to list files/folders inside it and I want to do it with UINavigationController so the user have the possibility to go back with "previous" button.
Both storyboard and programmatically approaches are ok.
Thanks you
Storyboards and segues are just a crutch. Think about how you would do this without them. At each level, to go down a level, you would just instantiate a new view controller and push it onto the navigation controller stack with pushViewController:animated:.
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/#//apple_ref/occ/instm/UINavigationController/pushViewController:animated:
And in fact it takes only one view controller class to do this, since any instance can create and push another instance of its own class. The display of one folder is exactly like the display of any other.
So if you wanted to configure this notion in a storyboard, you would have a circular segue, that is, the view controller would have a push / show segue leading to itself.
I agree with #matt's answer, just create the controller and push it. For sake of completeness, you can do this in a Storyboard with a segue.
Here's how:
So that you can call the segue programmatically, add an additional prototype cell to your tableView. (You do this because you don't want the segue to be automatically triggered when the tableViewCell is selected. By using an additional prototype cell, the segue can be wired up, but it will never be triggered automatically since this prototype cell will never actually be instantiated.)
Control-drag from this prototype cell to the viewController icon at the top of the tableViewController. Select "Show" from the pop-up.
Find this segue in the Document Outline View and give it an identifier such as "showFolderSegue" in the Attributes Inspector.
Now, when you want to trigger the segue, call: self.performSegueWithIdentifier("showFolderSegue", sender: self)
You can use prepareForSegue to set up the new tableViewController as you normally would.
This method too works with a single tableViewController.
I have a UIViewController with a UITableView that is fed with data from the local database. When the user first launches the app (after installing) the table view is empty and I display a UIView in the middle of the table view that contains a UIImage, a UILabel and a UIButton (a call to action).
The first version of this view I built programmatically, which was no good to me because every time I tweaked something I had to build the app again. Then I switched to the storyboard but had to drag a UIView to the middle of my tableView. It is working now but I don't like the way it is, I can't edit my table view cells without having to move the UIView out of the table view.
I'd like to have a way to build this view entirely separated from my tableView (or even from my view controller in question) and then reference it in the viewDidLoad call of my view controller.
Unfortunately Xcode does not allow us to drag views directly to the storyboard so I'm pretty lost here.
Please tell me if I haven't been clear enough. I appreciate any help you could give me.
UPDATE: It'd be particularly awesome to me if I could also create a custom Swift class for this view of mine and reference it in the storyboard. And then in my viewDidLoad I could simply instantiate my custom view.
Thanks in advance.
Create a XIB file in which you can drag a view (without a view controller).
In your code you can load the XIB using NSBundle.mainBundle().loadNibNamed("MyXibName", owner:self, options:nil).
In the XIB file you can give the UIView a custom class (like you can do with view controllers in storyboard).
You then of course have to retrieve the view from the array returned by loadNibNamed and cast it to your custom class.
I am new to developing apps for iOS devices, and I just tried out storyboard mode. I wanted to know if there was a way to change the function of the button,
for example, I have three pages, and on the first page I have two buttons, one that leads two the next page and a button that leads to the third page?
I would really appreciate an answer. Thanks
Cant you just control drag from the button to the page you want it to lead to? that is how storyboard works.
IMPORTANT: to go back you DO NOT create a button and make drag it back, instead you create a button and set the code for that button to dismiss the view controller.
You can still use the old method in Interface Builder : drag the IBAction to your button.
If you plan to use segues, you have to define the segue name in Properties, and implements - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender method.
I have created a Table View that has multiple Table View Cells of different styles - say "CellStyle1" and "CellStyle2".
The cells look different, but they should perform the same when selected - namely, segueing to the same new view.
I have set up both cells to have the same Storyboard Segue - "PushView", pointing to the same view controller.
This seems to work OK, but Xcode generates a warning: "Multiple segues with identifier"
How can I avoid this error? What is the right way to handle multiple custom cells that look differently but act the same and should segue to the same place?
This one has me scratching my head.
Thanks!
You could make one segue by ctrl dragging from the view controller to the destination view controller. And then assuming tapping the cell is the event that you want to trigger the segue, in didSelectRowAtIndexPath call performSegueWithIdentifier.
- (void)performSegueWithIdentifier:(NSString *)identifier sender:(id)sender
Or just give the 2 segues different identifiers and in prepereForSegue check for either identifier.