UITableView inside a UITableViewCell? What's the best design? - iphone

I've not found a answer to this question anywhere, but this seems like a typical problem: I am dynamically (from a xml file) creating a view to display "Questions" I take from the XML file. I am having problems to display multiple choice questions. I am trying following approach:
Question 1
MultipleChoiceQuestion 2
--First Option
--Second Option
--Third Option
Question 3
Question 4
MultipleChoiceQuestion 5
--First Option
--Second Option
and so on...
So, my Idea is: I have a first UITableView and row for each "normal" question , and a second UITableView for each "Multiple Choice" question that should be loaded into a row from the first UITableView as I showed before.
Is this a good approach or you guys have a better design pattern for this issue?
Thanks a lot!

There is a tutorial for creating custom UITableViewCells with UITableView inside it at:
http://iosstuff.wordpress.com/2011/06/29/adding-a-uitableview-inside-a-uitableviewcell/
iOS SDK is flexible and you can add any UIView subclass element to tableview cells. Have a look at 'Pulse', its a news reader app that won Apple Design Award. This app has horizontally scrollable images and its developers explained that how they used UITableViews to create that. So don't be afraid to implement new ideas no matter how wild they might appear.
Good Luck!

No, no! Please, no! Do not place big UI Elements like table views in a tableviewcell (and surely do not make them scrollable =P).
What about making the user be able to select a question (one question per row) and then show up a picker view with answers, on the place where to keyboard would normally be?
Just like a list of HTML select tags in Mobile Safari.
Or you can use a grouped table view with one group per question, including the chosable answers.

Related

Customize the background/border colors of a grouped table view using the solution of a previous post

I've read this post : How to customize the background/border colors of a grouped table view cell?
And I want to display a background cell. So I'm trying a use the previous post in the tableView function willDisplayCell.
No matter what I do, nothing is working. Could you help me out ? (My cells are 50pt high.)
Thanks
That question was posted two and a half years ago? for OS2 and then OS3. Probably not valid for OS4 or OS5.
An Apple engineer told me not to override drawrect like this as it was a "hack" and would likely break in a future OS version. So I would avoid doing that.

Iphone best way to define multiple ui components in a scroll

I have a questionary, and want to show multiple and different kind of questions in one page(a date picker, texbox, picker..etc.) These will be created runtime from an xml, and all these questions also will have their own;
-question labels
-a hidden label under the question for its validation alerts
-and maybe a few more labels around the question for explainaiton..etc.
So for each question on the page I need to use multiple controls, what is the best approach here:
-Use a scroll View and add my questions dynamically, but each question already has a few other components, how can I define this? can I create a view object for each question, add its components to the questions objcets and add questions to the scroll view? if so how?
-Or should I use table view I think it already categorizes the components you add in each cell?
-Or should I subclass some fancy Ui classes and do some fancy delegations? but how?
I am new to objective C so if answers are a bit explainatory I will be glad.
Thanks
Depends what you want from a design perspective, do you want to be able to go back to previous questions? and are the questions in a linear order? if so I would consider using UINavigationController to keep pushing new views onto the stack, each view would have a question.
Also, instead of having hidden uilabels for your alerts, consider using UIAlertView(it looks much cooler)
I reckon you should use a UITableView. You would then need to create few custom UITableViewCell in Interface Builder, one for each type of question you want to support.
It is probably the easiest way as the SDK provides almost everything you need. Moreover, you can find many tutorials and StackOverflow questions on the subject.

Editable UITableViewCell having a left-aligned label

I am very new to iphone application development and am struggling to create a table view page where each row contains a left-aligned label with an editable text next to it - just like how it works in the email account details page in the settings application on my iphone.
I have been googling the subject for hours and it is now somehow clear to me that I need to add UITextFields to UITableViewCells, but it is still not at all clear to me how I make these text fields take up the right amount of space:
How do I make the text fields align above each other?
How do I make the text fields expand as far as possible to the right?
How do I prevent the text fields from hiding part of the left-aligned label?
Read the Apple Docs on Tableviews there are a number of predefined table cells. Also look at the Tableview programming Guide. Pick the one that has the font characteristics that you want and Apple will take care of it for you. Also, in the Settings app, the settings are a Grouped style.
For the look you are describing I think it is called UITableViewCellStyleSubtitle.
You need custom UITableViewCells and there are a number of ways of making them. For your purposes, any one of the techniques detailed in the Apple documentation will probably suffice.
An alternative to those approaches is in GSUtils (full disclosure: open-source library written by me), where you can use the same approach to designing your table view cells as you would design a UIView.

Best approach to create a "settings" dialog page in iPhone [duplicate]

This question already has answers here:
How to create a UITableView with editable components?
(2 answers)
Closed 3 years ago.
I need to present the user with a screen with controls (i.e. a dialog). It will display some labels and different types of controls so that the user can do some configuration:
select a color (custom color picker)
select a line width (slider)
select one value from a list of values (UISegmentedControl?)
enable / disable one option (On/Off)
...
I am evaluating different alternatives:
Create the layout with labels and controls in InterfaceBuilder
Use a UITableView, so that each cell contains a label and its control
I like option 2 because it is similar to iPhone Settings app, and it makes the screen look organized, giving you sections, scroll..., but it is a real pain to create in code all different cell layouts, taking into account each row heights...
The solution has to be easiliy maintainable, allowing easy reuse of code, DRY (low repetition), data-driven...
Is there a recommended or standard aproach to do this?
Instead of implementing it yourself you might also like to consider some of the open source solutions. I use InAppSettingsKit in my app. There are a few minor UI glitches but it works well. I also evaluated mySettings (indeed I submitted a couple of patches) and InAppSettings.
Even if you don't use them, you might be able to crib a few ideas from them.
You can create the tableview cells in IB and then just create IBOutlets to each cell, and then return each cell in the data source method (forgotten the exact name of it, its where you normally create cells)
You could create a cell in IB for each cell or create different types of cells in IB, say one slider based cell, etc and programmatically change the text, etc.
This is staticly creating a tableview, theres an Apple guide on it somewhere.
you said it. use a UITableView and create custom UITableViewCells (probably in Interface Builder!) and add these in.
Also, as far as selecting a value from a list of values.. a drill in UITableView (embed the root UITableView in a navigation controller) with all the options and then a checkmark is probably advisable (this is how most apps handle this behavior). The On/Off button is more suited for UISegmentedControl.
There are great examples of this in this book.
Good luck.

Settings-style grouped table

So it's trivial to create a Settings style table on the iPhone. The problem is, they add a great deal of code as your Settings have a gamut of options/styled cells. One section might have a check list, another might have cells with accessory disclosures to drill down further, another might be labels with UITextFields.
My question here is, what's the cleanest way to go about creating this table. Do you typically create a subclass of UITableViewController and then subclass UITableViewCell for each different type of cells, and write supporting classes for those cells? Meaning if you have a Settings style table with 4 sections, all different types of cells, you will load 4 nibs into the table and import 4 class files? Programmatically set the frame, views, textfields and tag them for later access?
The answer(s) to this is probably subjective, but I'd like to know what you experts consider the most elegant approach to this common problem.
The easiest way to do this is to simply add your controls during the tableView:cellForRowAtIndexPath: method.
I also recommend this to help corral your code:
A technique for using UITableView and retaining your sanity
I would rather set most of the settings that I can in Interface Builder, instead of writing a whole bunch of code to make the visual/layout just right. As you can imagine, it will take quite a few rounds of "modify - build - test" in the iPhone Simulator to get this special table view laid out the way you want it.
I feel it's probably a bit easier to do all of these rough visual changes in IB, then load all of the custom UITableViewCell dynamically via their identifiers in code. You could then do one final round of tweaking on this code, if something that you want is not doable in IB.
Three20 library (extracted from Facebook iPhone app) has a set of ready-made cells that contain various controls.
(Not sure you want to use them, however. Three20 suffers from “not-invented-here” a little bit and tries to subclass and extend everything, so adding it adds quite a bit of a mess to your project. But at least you can use it as an example.)
P.S. Your question inspired me to open a “What are your favourite UITableView / UITableViewCell tricks?” thread on Stack Overflow, check it out for more tips.