Create a viewController or two tables in one? - ios

I am parsing an XML document containing two branches from one XML document of the same sort of item (Topics and Schools), connected by a tabBarController.
Right now, Topics is populated, but I do not know the right way to go about populating Schools:
Should I create another viewController for School, or have some kind of conditional statement/selector sharing space with Topics in the existing viewController?
If its the latter, then how?
I want to do this right the first time, Please know that I know almost nothing. Thank you.

If both information will be presented in the same way within a cell of the table, you should use the same viewcontroller, what will change is the datasource. You can create a custom init method with an additional type parameter which can assume the values "Topics" or "Schools" and based on this value fill the array, from xml file, with appropriate elements.

Related

How to implement two similar views efficiently in UISegmentedControl

I've two exactly similar views which I show in a two segmented control. Refer to image below. The differences between these two views is the parameter which I send to backend to fetch the values and the title. Even the returned values are same.
I've referred to some tutorial which cycles from one view to another when segment is selected .
I've ended up with two files with exactly same code. How to optimise this implementation so that I can implement with one piece of code only.
The two contained VCs have exactly same code to fetch values from backend and display. I've only one function which I've used in both VCs to fetch but there are other code sections such as Tableview delegations and other codes which are common to both.
In storyboard both are duplicate as well.
Is there anyway I can make it more efficient?
This could be a case for making your two view controllers be subclasses of a common superclass.
Or it could be even simpler: make them two instances of the same view controller class, which knows what to do because you pass a parameter at creation time telling it what to do.
For example, my Albumen app uses four view controllers, which differ primarily just in what query they perform on the user's music library. So I've elected to make them four instances of one view controller class, with an enum property saying which query it is, and any other varying functionality determined through switch statements on that enum.
I think you need to create only 1 VC ( In IB and code ) , put all the logic inside it and either
1- Add once instance / container of it to the MainVC and manage the process of selecting a segment to reload the content ( Recommended )
2- Add 2 instances of it to the MainVC and manage hide/show when the segment is selected

Best practice for displaying empty/non-empty results for a search in iOS xcode

So I want users to be able to enter a search query, and should it return an empty or non-empty result the appropriate view is displayed (shown below):
As I'm fairly new to iOS I thought about the following possible ways of implementing this. I'm not sure if any one of these is deemed as good practice or maybe another better solution exists:
Create two separate view controllers with their own views that will display a message for empty search results or show non-empty results respectively
Create a single view that will house all of the components and show/hide certain components based on whether or not the results are empty/non-empty
Create a single view, but programmatically implement the methods for drawing the relevant components and just initialise the VC with the respective designated initializer (one for empty and the other for non-empty results)
The best practice is to manage the empty state of tableview meaning have a single tableview and display data when available, if no data is available display a friendly message in the tableview itself.
Below is the link that will help you implement the code:
http://www.ryanwright.me/cookbook/ios/objc/uitableview/empy-table-message
There are ots of examples available on net for managing the empty state of tableview.

What are the best practices to create a TableView variable holder for iOS

I am suffering to find a way to create a table view variable holder that is able to hold the section and the data from that section, I told I had find a good way using the this structure
NSMutableDictionary[key,NSMutableArray[myClass]]
It work very well as far as I don't need to update the data in the class 'myClass' it hold all the sections in a dictionary and all the members of the section in the array however it has been impossible to delete or change the data from the array.
So my question is, what is the best practices to create a variable that hold details from a table view with sections?
I am using swift and XCode6

Two Tables in a single interface controller not working in WatchKit

I am trying to put two tables in a single interface controller in WatchKit, I am not able to populate the data in the second table but if I make second table as first table in UI than second table which becomes first is getting populated but not the other one. Any idea what could be the issue.
Thanks in advance.
I think this should be the same even if you are doing it from WatchKit.
First, you need to be set both the delegates to this interface controller either from code or from your storyboard. Once that's done, for every datasource or delegate function you need to identify which tableview is calling it and take actions from there.
Here's a similar post that should help you.
Multiple UITableview in Single Viewcontroller

using the same uitableview to reload data and use back button

Dont know how else to explain this but basically im using a uitableview to load data(core data) and have basically limitless lists and items. for instance list1 is food contains candy, starches, meat, and meat may contain beef, chicken, etc. if i click through the tableviews and get to chicken, how do i use the back button to go back to previous. I am just using "reload data" instead of multiple tableviews in storyboard. is there a better way to do this???
I started to set 3 values prevparentlist, subparentlist, and parentlist. but end up losing prevparentlist when you go to deep and it will only back up one level....didnt think this through.....please help
You just don't easily "reuse" tableViews.
If the storyboard gets too messy in your opinion the best way is creating a custom viewController (including XIB), set the original NSManagedObjectContext to it (as property) and also provide a NSPredicate which meets your criteria.
Then you'll push that viewController into your navigation stack.
ARC will take care of releasing the viewController and corresponding view if you setup the properties correctly.
I think this could be easily solved , you have to keep and int value and that keeps on increasing with table view did select and which will decrease on pressing back button. Depending on the int value you can load the table view data.

Resources