UITableView + UITableViewCell when UISegmentedControl is pressed - objective-c

I want to ask a question about UITableViewCell.
Apparently, this is what I want to achieve.
I have a page where I display one question at one time. So, when the UISegmentedController on the top right is pressed, I display another question and so on.
please see the picture attached or here: http://dl.dropbox.com/u/27303579/StackOverflow.jpg
Note that I use UITableView (Group style) to display my question. The question text is actually the Section Header.
*All the questions come from Web Service.
My question is:
What should I do when the NEXT (TOP RIGHT CORNER) button is pressed ? What can I do to refresh my page ? Do I need to reuse the current UITableView or how ?
Thanks a lot for your help guys. I hope I make myself clear. really appreciate it !

When the arrow is pressed you can update the data in whatever data structure you have that populates your table cells, and then call [self.tableView reloadData]. This will trigger the UITableViewDataSource functions again, using the data structure to repopulate your table. Of course, cellForRowAtIndexPath will need some handling so that it knows how to draw the cells based on what data they are supposed to display.

Related

UITableView Cell - Edit?

Is it possible to use a UITableView to be able to enter a value into a database's field.
For example, if I was to have a UITableView pointing to a field within a database and if I wanted to enter a new entry into the database - tap on the UITableView Cell that would then allow keyboard input into the cell which ultimately end up being a new record in the database??
This is possible, but if something is possible doesn't mean you should be doing so.
You might ask why?
Well! you are trying to input data from view directly to database, this is a very bad practice. There are many reason for it being bad, the major is efficiency and security reasons.
You should consider using MVC pattern.
Now since its completely possible, I will explain the idea on how to do it and conclude with links that will have real code examples.
In tableView:cellForRowAtIndexPath:
add a TextField with tag (to get the reference back in future) and add it to contentView of the cell and have it hidden.
Now in tableView:didSelectRowAtIndexPath: make the cells editing property to YES.
Then, in tableView:willBeginEditingRowAtIndexPath:
get the reference to the textfield in contentview using viewWithTag: method and hide the textLabela and unhide the textfield.
In textfield's delegate textFieldDidEndEditing: make cell's editing property as no (yea, you need to keep the reference) unhide the textlabel and hide textfield.
In tableView:didEndEditingRowAtIndexPath: write methods which will commit the changes to your db.
Below are list of links which will get you code examples:
Having a UITextField in a UITableViewCell
Accessing UITextField in a custom UITableViewCell
iOS Database Tutorial
There are no examples for your requirement 'coz it bit bad way of doing things.
Yes its possible....
You can use delegate methods to take data form you cells textfield to your parent view controller and then save data in database.

List with 3 columns editable on the fly

I want to add in an iOS App a list with 3 columns, but I also want that each field could be editable on the fly by clicking directly on it and when I press return it saves the field.
Currently I am using Xcode 4.6.1 and storyboard.
Here is the idea:
Because I am a beginner, I am asking you if there is a way to do that by using the UITableViewCell, UITextField and UITextView or there is something else to create this list faster.
Can you provide me some links with tutorials or similar, please?
Another question is: because each field (Label1,1; Label1,2; L1,3) will refer to the same object (eg.: cable; [size]1 meter; [diameter]1 cm), is it better to put each row in a NSMutuableArray or put everything in a SQLLite Database?
Hope in some hints.
You can create custom cell. I answered how to do it here
And add gesture recognizers for each object on the cell.
Change values and reload data.

How to update UITableView after adding/ updating data

I am newbie for iPhone application. For storing data, I am following this tutorial.
I understand how to save data and retrieve the same.
What I am wanted to do is instead of another UITableViewController (first screen in storyboard, where we have list), I will drag a UITableView and show list of items there instead of showing in another screen.
Any idea/ suggestion how to get this done?
Any hints would be greatfull.
What I feel is, I would need to add UITableView. Add delegate and dataSource method on it and add a method where I will have all data shown in UITableView.
Edit 1
What I want is ONLY ONE SCREEN. In the link that I have provided, it is second screen.
That should work fine. But make sure you also have done a
[tableview reloadData];
after you've changed the data in your table view data source delegate.
What I am wanted to do is instead of another UITableViewController (first screen in storyboard, where we have list), I will drag a UITableView and show list of items there instead of showing in another screen.
Why you want to do this way?
UX will not be at best.
What I feel is, I would need to add UITableView. Add delegate and dataSource method on it and add a method where I will have all data shown in UITableView.
Even if you want to do, yes you need to set delegate and datasource methods.

UITableView with UISearchDisplay and Checkmarks

I´ve got a TableView with a Searchdisplay and when the user tabs on a cell, the cell accessoryType toggles between none and checkmark. That works fine, when i´m using only the tableview. But when I select a cell while i´m using the searchdisplay, the selection won't be applied to the "normal" tableview.
Maik
can you show me or tell me which type of data you are showing on table. and are you using a simple array? i have a method for solve this problem.
NOW i give you a tips when set chekmark you need to make changes in orignal array.How?When will you explain it. Then i can give you good method to do this.

2 Questions about customizing a UITableView

I have 2 questions that I am having trouble answering.
I have a UITableView and when you touch a cell, it changes its height and inserts a sub view with some detail.
The problem is that when I select another cell, there is no obvious way to collapse the other cell. What I did as a temporary fix is run a loop whenever you select a cell, and on each cell, if its not the one you selected, it collapses it. This does not seem efficient, does anyone have an idea?
Second question is, whenever I collapse a cell, it animates. but it removes the detail subview kind of jarringly, is there a way to wait till the cell is done animating to remove it? I cannot find an appropriate delegate method.
Thanks in advance.
Perhaps the best way would be to have a variable that stores the index path (row) of the previously touched cell. Then, test to see if the current cell's index is not equal to the previous, collapse the previous cell and open the new one.
For your second issue, can you not animate the collapse before you remove the subview? I assume you're using [UIView beginAnimations] (or something similar). Set the duration of the animation [UIView setAnimationDuration:1.0], and then after you commit the animations, do [self performSelector:#selector(collapseCell) withObject:nil afterDelay:1.0].
I've not tested this, and I'm going off of memory, so sorry if it doesn't work as you'd hoped, but perhaps it can get you going in the right direction.
Edit: Apologies, I didn't see your "Core Animation" tag. The second solution may not be right for you.