2 Questions about customizing a UITableView - objective-c

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.

Related

UITableViewCell Height Calculation and delegation?

I know this question had been asked hundreds of times before, but it's never really been solved (Or at least the way I'd like it to be). I have a rather complex UITableViewCell setup. The cell.backgroundView is loaded from a UIView subclass which uses a fair bit of CoreGraphics and CoreText. The code is rife with CTFramesetterSuggestFrameSizeWithConstraints, so I'm relectant to duplicate the class in the heightForRowAtIndexPath method.
I think I can solve this by creating an NSMutableDictionary with the indexPath as the key and the height as the value. But then I'm faced with the problem of heightForRowAtIndexPath being called first. I believe I can solve this problem by guessing the height of the cell and then once the cell's UIView subclass has finished rendering, use delegation to set the cell's height.
But this leaves me with the problem, how the hell do I delegate this? And, how to I prevent scrolling from being extremely choppy? as the cells will be created and resized in a split second.
In the past, I've used a dummy cell. I have a separate method -fillInCell:forRowAtIndexPath: which puts data into the cell. That way I can fill out the dummy cell in -tableView:heightForRowAtIndexPath: and the real cell in -tableView:cellForRowAtIndexPath:.
If this does not work for you then there are other options.
The first thing that comes to mind is create real cells in -tableView:heightForRowAtIndexPath: instead of -tableView:cellForRowAtIndexPath:. You can store completed cells in a mutable dictionary. -tableView:cellForRowAtIndexPath: will simply pull the completed cell from the dictionary. You should also detect when scrolling has stopped so you can empty your dictionary (just because -tableView:heightForRowAtIndexPath: was called doesn't mean -tableView:cellForRowAtIndexPath: will get call for the same indexPath).
Hope that helps.

UITableView + UITableViewCell when UISegmentedControl is pressed

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.

NSOutlineView selection does not work

I have an NSOutlineView with a custom datasource (I don't know if this is relevant).
I have only one column (again, I don't know if this is relevant) and I want to perform a specific action upon cell selection, so I thought I should override outlineViewSelectionDidChange. This what I did:
-(void)outlineViewSelectionDidChange:(NSNotification *)notification
{
NSLog(#"selection changed");
}
But this is not working. I have been playing around in IB with the Outline View, the Table Column and the Text Field Cell properties but so far I had no luck. I don't know if I changed any property that caused this situation or if this is something specific to my specific implementation.
So, anyone's got any clue on what I may be missing?
EDIT: Just in case I'm mis-interpreting the selection concept within an OutlineView, I expected the cells to be selected if I just click on the text outside the area of the expand arrow.
Well after a long struggle, as always, just after I posted my question, I found the answer. The problem is I am using the NSOutlineView in an NSPanel and somehow the NSPanel is not allowing the cells to be selected. If I just move the NSOutlineView to an NSWindow it works just as intended.

Prevent updates to NSFetchedResultsController whilst table view is in edit mode

I am using an NSFetchedResultsController with a data source that is updated in the background. This is working really well - as new objects are saved to the managed context they appear in the UITableView. However, this leads to the problem I'm having.
When you swipe to delete a cell, putting the cell into edit mode, if at that point an object is created which pushes the cell down in the table view, the position which the cell occupied will be in edit mode, and not the cell you selected. Basically, the UITableView retains the edit mode on the original index path, without adjusting for the movement of cells.
Is there any way to get around this? Thus far everything I've tried has lead to a dead end.
reminds me of a problem i had when reordering uitableview cells.Look at 'Responding to changes' in NSFetchedResultsController reference. It shows a way to temporarily disable the change notification. I used it for reordering, maybe you can get inspiration from it to solve your problem too.
kind regards
y

UITableView strange issue

I have a UITableView with around 10 cells, placed in a view controller in the middle of a program. When I run the program, the table view shows. But if I start quickly selecting random UITableViewCells, the program crashes. I don't know how this is possible because I can do it in another application with a UITableView and nothing interesting happens. How????
EDIT: Nevermind. I fixed it by removing some unnecessary statements.
Check with your coding.May be you have done some silly mistake at the time assigning text to the cells are some where else. Look into your coding.
For your reference you can refer this link.
http://iphonesdevsdk.blogspot.com/2011/04/uitableview.html