implementation of collapsing tableView Cells - iphone

so I wanted to have a table with multiple sections and each one with multiple cells. By touching a section's header, this section should expand and the others should minimize, leaving only the header visible.
I looked up some suggestions and accomplished this by a) setting the cell's height to 0 and reloding the data animated and b) adding a button as a subview to the cell's header.
Anyway, while it works fine, mainly, there is minor problem, namely, I can see a 'flickering' below each cell's header, when the change is animated. I guess its because the cell's content is redrawn. And I don't like it!
I wanted to ask whether the approach is correct or generally your opinion about it. Moreover I would be really happy, if someone could hint me why the 'flickering' appears in my table :)
EDIT: Another thing is, that if I press on a section, it appears like all the section headers are pressed.... maybe someone has seen this weird artifact also?

You should remove cells instead of setting height to 0.
You will have less call to data source and delegate and no more artifacts.

Related

Self sizing cell makes views to stretch

I tried to make self-sizing cells. I got it to work but with some bug. Which I think is because of wrong constraits. So I kindly ask you if you could look them.
Problem is that after scrolling in tableview, all my views are going to stretch. I thought that it would happen because of not setting height constraint but it seems not to be problem.
Illustration(pretty normal):
After scrolling and coming back up:
And these are my constraints for this view which all of them looks good to me:
And if you want to know how I made cells to resize, then like this:
tableView.estimatedRowHeight = 105//Because my row height is 105
tableView.rowHeight = UITableViewAutomaticDimension
When this sort of thing happens, the implication is that you are not supplying sufficient constraints to size the cell's contentView from the inside out. You can readily confirm this using View Debugging to pause the app when you see your incorrectly sized cell; you will then be able to study the actual values of your constraints and see what the problem is.
EDIT Now that you've posted your constraints, it's easy to see what the problem is: There is nothing at all connecting your interface elements to the bottom of the contentView. But that is the whole point of self-sizing cells: you must have, as I already said, sufficient constraints running all the way from the top of the contentView to the bottom of the contentView. That is what determines the height — and so you are not determining it.

Non sticky header section cell (supplementaryview) on collectionview

Okay so here is the struggle, the default behavior for header section cells is to stick to the top of the collection view frame, did some digging and couldn't find a way to remove this default behavior, if anyone has clues about how to do it, please share.
The main reason for this is that I want to display a header as a UIView on top of the collectionView so if the section header does not scroll with the rest it kinda sucks in terms of UI experience IMO.
Set the flow layout's sectionHeadersPinToVisibleBounds to false.

IOS IPhone label moving when screen scrolled

I appreciate that this is probably something people will need code samples to properly answer but unfortunately I don't have them to hand at the moment so I'm asking for peoples experiences and whether they've seen anything like this before.
I have a view with a UITableView in it, there are a bunch of cells and on this particular view if I scroll the screen down then the label that's in the last cell superimposes itself on top of the label in the first cell.
It only happens on this one view where the first and last cells appear or don't appear in the UITableView depending on whether certain values are in a JSON feed.
If both cells are in the UITableView then when you scroll, the label of the bottom one appears on top of the top one. The bottom cell's label is still in place, as is the top one - just with the bottom one on top of it!
So, has anyone seen anything like this and if so is there's an obvious thing I'm doing wrong that this type of occurrence is a symptom of?
How to look for the cell being dequeued?
Check out [UITableViewCell prepareForReuse] and that's where you can remove previously inserted subview(s) before adding new ones.
Here's the Apple documentation:
http://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewCell_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableViewCell/prepareForReuse

Any ideas on how to make a UIPickerView from scratch?

I've decided that I don't want to ever use UIPickerView again... it's completely inflexible in terms of functionality, design, and size (height). It also occasionally gets stuck between rows, and the delay that occurs between letting go of a wheel and when the delegate method is fired indicating that a new row has been selected (because of the "settling in" animation) has caused lots of problems in the context of the apps I've been working on.
That being said, the user-friendly aspects of UIPickerView are good, and I'd like to try to replicate it. I've tried to research different ways that this might be done, but without much success. Does anyone have any ideas as to what would be involved to make something similar from scratch?
I was trying to get a UITableView subclass to behave in such a way that whatever cell was currently in the middle of the table (it would change while dragging, etc.) would change its background colour to something different implying that it was "selected". As soon as the table was dragged such that the "selected" cell was no longer in the middle, the cell would go back to normal and the new middle cell would change colour. So this would be like UIPickerView in a sense that you don't have to tap on a cell; instead you just drag to have one selected by default.
I figured it should have been easy enough to intercept the "touchesMoved" method of UITableView and add some code that looped through all currently viewable cells in the table, checking to see if their frames overlapped the center point of the table, and changing their appearance accordingly (plus sending a notification to other classes as needed to indicate the "selection" change). Unfortunately, I can't get this to work, as the "touchesMoved" method doesn't get called when I drag the table. Am I missing something obvious?
Any ideas or suggestions would be very much appreciated at this point... I made an app that relied heavily on UIPickerView objects, and because of the problems I've run into with them, I'll have to abandon it unless I can figure out a way to make this work.
Thanks very much,
Chris
Remember that a UITableView is a subclass of a UIScrollView, and the UITableViewDelegate gets all the UIScrollViewDelegate method calls too. scrollViewDidScroll: sounds like it would easily fit the bill for knowing when the table view was scrolled.
As for finding which row is in the middle of the view, just use indexPathForRowAtPoint:.

Broken cell with an odd strikethrough?

I'm having a weird issue with a particular UITableView in my iPhone devel experience here. If you look at the following screenshot:
alt text http://dl-client.getdropbox.com/u/57676/brokencell.png
you'll notice a strike through going through the middle of the 'Jane Aba' cell.
Any idea what might be causing this odd graphic display? It's true for both the simulator and for the actual device running 2.2 SDK.
As requested, here's my -tableView:cellForRowIndexPath: method:
* EDIT *
I've located the problem. I'm not entirely sure why this is the problem, but it is. In my RootViewController, I have the following line of code in my -initWithCoder: method:
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
When I comment that out, the cell (which is not in the RootViewController, but a secondary controller) it's resolved. Any idea why this might be the case?
I've had a similar problem. For me, the single line was caused by a superfluous view that was created but never sized or placed correctly and so was 1 pixel high, floating over everything else. You can also cause this by confusing a UINavigationController about its set of subviews (by adding views directly to its layout container).
Look through your UI (xib files and programmatically created views) for a view that shouldn't be there or is otherwise not being used. It might be helpful to write some code to dump a UI Hierarchy, so you can see what views are where.
Are you doing anything special in your -tableView:heightForRowAtIndexPath: method?
It looks to me like the height of the row is being set incorrectly, so the contents of the cell are expanding outside of its bounds.
The problem disappears when you set the cell height for the table view to 1 pixel in IB. It seems that before you populate the table, an empty table is drawn with the outlines of the cell height set in IB.
Don't set the cell height to 0. IB doesn't like that. :-)