iPHONE SDK - tableview, remembering how much it is scrolled? - iphone

i was wondering how do i do this?
I wish to make a tableview configured in a way that if i scroll down a tableview and click on one row, i will be brought to another view. But when i click a back button of some sort. i return to the tableview but still viewing that particular row. kinda like the iPod table in the iPhone? Remembering scrolled position?
i just want to know how to do the 'remembering scrolled position' part.

Save your index path in tableView:didSelectCellAtIndexPath: before pushing the new view, use it later. This will give you the NSIndexPath pointing at the cell that was selected by the user, not necessarily give you the same position it was at before they tapped the item. So keep that in mind.

Continue from jer's answer. You can use indexPath when calling this method in tableView:
UITableView selectRowAtIndexPath:animated:scrollPosition:

Related

cell animation, uitableview cell

I was downloading an Pizza pizza application for IPhone. There is very cool animation for a cell.
If you click on particular cell, it will expand down and show you more controllers.
Please look at link1 (first state ) and at link2 (second state when you are clicking on the cell)
Question : what is the right way to achieve this animation.
Please advice me on this issue. Any comments are welcomed
There is nothing new about this animation. Its pretty straight forward, and it will just depend on how you want to effect this change.
For example, start off with the cells as shown in your first image. Touching a cell will call the -didSelectRowAtIndexPath, and you will need to increase the size of the cell, and provide the new cell (which is the image of the second link). Call tableView reloadData to effect this change. UseUIAnimation that will animate the cell from your first state to second state for a period of 0.5 seconds (how fast you want it to be)
Make sure that during the animation period, your cell is NOT selectable.
cell.userInteractionEnabled = NO
You can do this with other animation frameworks, but UIAnimation should do the trick. (Refer to examples of UIAnimation if you need help with it)
Every cell you see is a section Header View with button.When you touch the button,the table reload data in this section,then you can see the real cell view in this section. The cell view is a custom view with a lot of controllers.

image is reverting to original when scrolling uitableview

I have a button inside each cell. When it's pressed, the image is changed (basically a checkbox) to denote a selection. When you scroll to the bottom ... then scroll back up to the top. The image is reverted to the original image.
This question is pretty similar to this:
Preserve Cell Image After Scrolling UITableView
And others. But, I can't seem to find a good answer. I understand that's it's reverting back to how the uitableview is setup when the cell goes off the screen. But, how do I save the changed image to the uitableview so when it scrolls it doesn't revert to the original?
Thanks in advance! =)
It's changing back because cells are reused. When your cell is going off the screen it is taken out of the view and put back into the reuse pool. Then you're getting it out of the queue again in cellForRowAtIndexPath and setting it back up as the default.
The question you linked to is exactly what you should follow. You should store the state of your cell in your view controller and then when you set it up again in cellForRowAtIndexPath you should load that state and set up the cell appropriately.
One simple way for your method would be to have an NSArray which you set up to be the same size as the number of rows in your table and then in that just store an NSNumber for each row which contains a boolean value on or off for your selection state. When the user toggles, toggle the value in the array and then in cellForRowAtIndexPath read that value and set it up appropriately.
I'm assuming the checkbox in your table view cell is changing state to a selected state because a user selected it. You shouldn't use UI elements to maintain the state of your app. That is, when the user taps the checkbox, you should use that event to somehow reflect that state change in a data object in your app. Then, when that cell needs to be displayed again, you configure it with the state you previously saved. This allows for things like cell reuse, and view unloading and is all-around a good habit.

iphone sdk stay the selection colour of cell in UItableview?

How to get the selection cell still in the selected state in uitableview. Actually I am pushing a view from a tableview when came back then the selection cell is deseleted. I want to be show the previous selection cell when came back also how to do that.
In didselectrowatindexpath use the method selectRowAtIndexPath:animated:scrollPosition: and the row stays selected.
when you are going and coming back from anotherview make sure that save the selectedCell and then in viewwillappear method reloaddata.In cellforindexpath write the code of selection style uitableviewcellselectionstyleblue.
first, you can store the selected indexPath in user default in the didSelectRowAtIndexPath method.(maybe you can store a indexPath that is bigger than your table view's row count to indicate initialization stage, which means that no row has ever been selected)
then, you can load the stored indexPath in the viewDidLoad method using
tableView selectRowAtIndexPath:<#(NSIndexPath *)#> animated:<#(BOOL)#> scrollPosition:<#(UITableViewScrollPosition)#>
meanwhile, you can do some check (like mentioned above or something else) to check if there's nothing selected yet.(saving a bool in user defaults works, too)

How to determine if scrolling a UITableView was done by tapping the index?

I want to determine when the index (transparent alphabet) along the side of a UITableView is tapped. To be more specific, I have a sectioned UITableView that has an index, and said index does the right thing, but when the UITableView's -scrollViewDidScroll method is called, I want to be able to determine if said scrolling was the result of the user tapping the index, vs. dragging or swiping the table view itself. If anyone has ideas on how to do this, i'd love to hear about them :-)
Regards,
John
You could override touchesBegan to monitor the location of any touch event that precedes scrollViewDidScroll.

How are touches handled by a UITableView?

I'm trying to better understand how UITableView and UITableViewCell work, and one part of that is touch handling.
So when I touch a row on a table view, what exactly happens? My basic understanding is:
UITableView is a UIScrollView, so first it checks if it's a touch or a scroll
If it's not a scroll then the touch gets analyzed to see which row is under the touchpoint
It gets the cell at this indexPath (how?) and tells it to setHighLighted, setSeletected
Is that it? Does anybody have a more thorough understanding of it than that?
Probably somethign along the lines you mentioned, you never know though until you see t he source, why do you want to know anyway? you making your own tableview?
One last step is that the touch gets passed to the cells content view. That way any subviews in the cell will receive touch events. I'm pretty sure this comes after your step 3 and actions from cell selection will be processed first.