I have 2 UIViews into a UIView. I'm using this because I want to show an object and if is photo type or text type, I'm using a view or other. Using this I can do it with only one segue, and not 2 going to 2 different viewControllers.
It's a good practise or I have to create 2 viewControllers and make 2 segues?
I'm using hidden properties to hide or show views.
self.photoView.hidden = YES;
self.textView.hidden = NO;
Thanks!!
This is a good practice but you should use a state pattern
Make sure that you show only one at the time and handle hide and show updates.
In your situation you have one view and 2 subviews. This is totally fine.
But if you get more complex View structure maybe it's better to make 2 separate viewControllers or one ViewController but with 2 custom Views.
Related
I have one UIViewController with two UIViews on it. In the Navigation bar, when one button is pushed one of the UIViews is displayed and when the other button is pushed the other UIView is displayed. I want to put a UITableView on one of the views. However, the UITableView requires the UIViewController to use the UITableViewDelegate and UITableViewDataSource. Having implemented this for my UIView (subview) containing the UTTableView, when I click on the button for the other view, which does not contain a table, I get errors and the application croaks.
I am assuming (possibly incorrectly) that my issue is that I am trying to use the same UIViewController for both subviews, but only one contains a table.
Question 1) Is it possible to do what I described above? Meaning, if I had a problem then something was not connected up correctly.
So, I went down a path of creating two separate UIViewControllers; one for each view. Not sure this is the smart approach. Now I am just looking for advice on the best way to do this. Thank you in advance for your help.
To be more clear about what I am trying to do. I want the blue view to be put where the pink view is when the first button on the bar is clicked and I want the yellow view to be put where the pink view is when the second button is clicked. Essentially the pink view will never be displayed and may not even need to be on the UtilityViewController.
Having each as a UIViewController (or a subclass thereof) is the way to go about what you are trying to do. The UITabBarController does this already: https://developer.apple.com/library/ios/documentation/uikit/reference/UITabBarController_Class/Reference/Reference.html
I have a controller that will send a set of data to the view. This set of data must be viewable in two different ways (no, this is not about landscape/portrait), thus two different views. My question is, how do I create these two views, linked to one controller, using storyboard? I want to be able to see and edit both views without doing any ugly tricks.
In my experience it gets a bit messy when trying to deal with different "main" views in the context of one controller no matter what you do.
Basically you need to create another view right on top of your UIViewController's view in storyboard and make it hidden, connect its outlets to the controller and when a button that flips your presentation styles gets hit you need to either show or hide your second representation view like this:
- (void)btnAction:(id)sender {
self.secondView.hidden = !self.secondView.hidden;
}
So, this is my question. I have a ViewController, and I want to add 2 different Views in different position (one upper and the other lower) but they will appear at the same time, using method "addSubview", but I don't know if this is correct, to have different subViews in one Viewcontroler?
I'm not using Storyboards, I'm using XCode4.1 to iOs 4.3
You mix up views and view controllers.
The number of views that a view controller can control to display its data and perform its business logic is not strictly limited.
Nor is the number of subviews limited that a view can have.
There is just one thing. When these views are rather independent from each other, then do not make one a subview of the other. If a is the underlying view and b and c are the indipendent subviews, then do:
[a addSubView:b];
[a addSubView:c];
Where is the problem?
I want to use the same TableView for 3 of my tabs instead of using 3 identical TableViews. I created three navigation controllers (one for each of the tabs) and linked them to the same Table View Controller But if I run the app with the storyboard like the picture below, it works for the first one of the sharing tabs, but for the other two I get a black screen where the tableView should be. So I want to know if it is even possible to make it work with this setup?
I'm trying this, so I don't have to make a litte change in the tableview 3 times.. The 3 tabs are populated with the same data too, just filtered differently, so just filter the array depending on which parent navigation controller would be simple I suppose.. But I need to know if this is a possible way of sharing view or not.
I would suggest a different approach. Just have three different table views. But since the question is not about being the right approach, I would say that the best way to do it is to do it by code, removing the tableview from the super view (The view controller's view) and moving it to a new view controller when the delegate from the tabbarcontroller is called. Keep in mind that you will also have to assign the delegate and datasource for each view controller.
This is a question regarding iPhone objective C design. How can I have 2 UIViewControllers manage the same view? Each UIViewController will be created at different times, but their views are essentially the same thing.
To help explain, here's an example:
Let's say I have one ViewController that synchronizes a list of tasks from the server, allows the user to edit/delete these tasks, and displays other information on the view (like status messages), etc. At a separate time, I want to show a "read-only" list of those tasks using the same view (since the view has already been created, tableView is created, status message textbox is there etc.), but based on different things, I want this view to act differently and update different status messages.
So in this example, I want to reuse the view but use 2 different controllers depending on where the user is. If he/she is in edit mode, display UIViewController 1 which manipulates VIEW 1. If he/she is in read mode, display UIViewController 2 which manipulates VIEW 1.
I'm wondering the best way to design this if this is 1. possible or 2. should I just duplicate VIEW 1 as VIEW 2 and have UIViewController 2 manage VIEW 2, even though they'd be the exact same.
Thanks in advance for your help.
Create a base UIViewController class that each of yours descend from. Put all of the common interface element declarations (either plain ivars or IBOutlets) in the base class. If you use InterfaceBuilder then make the files owner the base class.