Using a shared TableView for 3 of my tabs - objective-c

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.

Related

Use UIViews into UIViews

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.

Two views of one controller presenting the same data in different ways - possible using storyboard?

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;
}

How to Create UITabController on a Button Click

I am working on app. It has normal 3 views. On third view, I have a table view. If I select any row, I want a view which contains UITabController. I have created a simple UITabController app, but unable to do this. How to do this ?
thanks in advance
IMHO, your question is perhaps ill conceived.
A tab bar controller controls view controllers which in turn control views. Your suggestion that a view contains a controller of controller simply does not make sense.
Maybe what you really want on selecting a row in your table view is to present a new view controller and then make the (existing) tab bar visible.
You usually want a UITabBar to be THE navigation for your application and not show it later on one view.
But if you want to do so you should show, as Mundi said, a new UITabBarViewController when you select your UITableViewCell.
I don't know your exact usecase, but if you work with a UITableView I would use a UINavigationController to push a new View when you tap one UITableViewCell. Then it may be better (If you have 2-3 Elements) to use a UISegmentedControl in the UINavigationBar. This would look like this.

Can you assign different buttons for different views using a split view controller?

I am creating a split view ipad app. I have four buttons in the master view which segue to four different views. However, when I am in certain views I don't need all of those buttons to display in the toolbar. So basically, is it possible to change the buttons for different views in a split view controller? any advice, tutorials, or source code would be sweet
Adding to what Lu Yuan said. You could put a pointer to the instance of the master view in your app delegate so that when one of your subviews load, it can get the master view instance. Then you can hide which ever master view buttons you want.

Overlapping UIViewController subview content despite separate navigation controllers

I have a custom UIViewController called ProductDetailViewController, it has lots of subviews and each of the subviews' content is populated by data requested from a remote server.
There are two ways you could end up looking at a product detail view: in one tab of a tab bar controller you can browse to a product and one gets pushed onto the stack of the navigation controller specific to that tab, or in the other tab you can scan a barcode and a ProductDetailViewController gets pushed onto a separate navigation controller within that tab.
The strange thing happening is that if you have a product detail up in one tab, and then bring one up in the other, when you switch back to the first tab you see overlapping duplicate subview content, as in there are two labels/product images/tableviews stacked on one another within the one view.
FYI:
Nothing ever goes wrong with the second instance you push onto a nav controller stack, it's always the first one that this happens to, as if subviews were added into the existing controller as well as the new instance. I don't think there are two entire product detail views being stacked - the view has a solid background color, so it would hide the one beneath. I'm quite certain I'm pushing to separate nav controllers. At first I thought maybe the incoming data was being sent to both controllers, but that wouldn't account for multiple instances of UI elements overlapping.
Has anybody ever run into anything like this? It's a first for me for sure, and it's driving me nuts.
Screenshot of overlapping product name label subviews:
Somewhere in your code you have a lot of [myview addSubview:anothersubview]
Probably you duplicating subviews when you updating ProductDetailViewController.
Try to insert next code before u start to populate all subviews
[[myview subviews] makeObjectsPerformSelector:#selector(removeFromSuperview)];
The issue is that many of the subviews aren't actually created until data is received, and the application makes use of NSNotificationCenter to determine when data has been returned and what class and function should receive it. I should have mentioned the use of NSNotificationCenter initially, but it hadn't crossed my mind that it could be this type of problem.
I send a string to my API response notification class as an identifier, and by changing that from being the same between all ProductDetailViewControllers, to a unique value by concatenating the requested URL to my string, my problem has been solved.