While using Storyboard I constantly found myself looking for ways to completely eliminate the need for nib files in my project. Using UIViewControllers for each main view in my application, laid out in storyboard, and using dynamic UITableViewControllers with custom cells got rid of about half of them, but I was still trying to find a solution for creating a partial view to be used in multiple UIViewControllers that wasn’t contained in a separate nib/xib file.
I eventually stumbled onto the following line of code:
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"ProjectButton"];
This line of code allowed me to drag a UIViewController into Interface Builder and, using the “Identifier” property, call it into my current controller like so:
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"ProjectButton"]; UIView *view = [controller view];
I can then use tags to grab each piece of the view, the same way you would with a custom UITableViewCell:
UIButton *button = (UIButton *)[view viewWithTag:1]; UILabel *label = (UILabel *)[view viewWithTag:2];
This method allowed me to keep all of my related views inside a single storyboard
No comments yet.
Leave a Reply
You must be logged in to post a comment.
<< Blur UIImage