UITableView has a custom section header view which disappears - iphone

The tableview, custom table header, and custom section headers are loaded from a NIB. The tableview is grouped.
When the view loads, the first section header doesn't show up. If I scroll down, the other section headers will appear at first, but will disappear as soon as the section above them touches the top of the screen.
If I scroll back up so that a disappeared section header is off the screen, then scroll back down, it will usually reappear.
The problem is fairly consistent but not entirely- sometimes I have to scroll up and down several times to get a header to reappear. Any ideas as to what could cause this?

I fixed it- I was using one UIView for 3 sections, changing the text appropriately then returning it. Creating separate UIViews in the NIB for each section fixed the problem. So I guess you can't do that.

Your custom views must be (or descend from) UILable or UIImageView objects. You may need to manually set row height for the headers to get custom views to load and display properly.
You should review the details in the UITableViewDelegate protocol.
Specifically, look at these methods:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
and
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
Part of the discussion on the tableView:viewForHeaderInSection: method states:
This method only works correctly when tableView:heightForHeaderInSection: is also implemented.

Related

How to place two buttons on top of tableview

i have been looking, but can't find my answer.
my question is how to make a tableview with two buttons above it.
here is a pic of something i would like to do.
I have the grouped tableview, but can't figure out how to make it look like the image.
thanks for the help
http://img137.imageshack.us/i/imagezjb.png/
Create a view with your two buttons as subviews, then set the tableHeaderView property on your table view to be that view.
#LucasTizma's answer is valid but you can also return views for header sections by implementing the method below, which returns a UIView. In this case, you will be able to return different views for different header sections so if for instance you had a header for Games and a header for Utilities on the same tableView, you could return different images/buttons for each header (i.e. a special game promo in the game section and a different one for Utilities).
Basically the process is the same: you create a UIView, add the buttons/images as subviews and then return it on the method.
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
Cheers,
Rog

Decrease UITableViewCell width and put custom button on the left

Is there any way to decrease the standard width of grouped UITableViewCell and put a custom button on the left side(outside of cell boundary)? I tried to change the cell size but it keeps same
You are going to have to fake the editing mode.
What I mean by that is that as AtomRiot said you have to subclass UITableViewCell so that when in editing mode you show the button you want on the left, outside the cell.
But first things first.
To change the indentation level for your cells all you need to do is implement this delegate method for the UITableView
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
So that takes care of it. Then in your UITableViewCell subclass all I would do is to implement the method
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
which I assume is called when the table the cell belongs to has changed to editing mode.
There I would fade in (or animate in any way you want) a button to appear on the left of your cell.
I have done it inside a grouped-style cell but never on the outside.
Give it a try!
You could subclass UITableCell and add your own custom views inside of it. I have not personally added a button inside one but it should work. It may get confused with the row selected call the tableview makes if you are implementing that.
The Cocoanetics blog seems to have a pretty good solution to this:
http://www.cocoanetics.com/2010/03/how-to-shrink-cells/

How to decrease width of table view cells for iphone

I'm trying to create a grouped table view with two sections. For the first section I would like the width to be only half the screen. For the second section it would be the standard width. Also, next to the first section I would like to put a button.
How is this done?
Thanks!
To put a button in a section what I've done in the past is create a section that has no rows in it. Then, I respond to the - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section method with a view that contains a button that is rigged to whatever delegate I need. This will give you the appearance of having a button sitting in a section with no data. This is how buttons appear in the Contacts view/edit screens in the stock iPhone apps.
Table view sections are fixed with to the size of the screen. If you want the individual cells to appear narrower in one section and wider in another, then you can control the size of the view itself with the data source delegate, though you might have to set the background of the table view to transparent so users can actually see the smaller view on top of the table view.

UITableView Header View Scrolls

I am using a header view, not section header, with my UITableView. The documentation says that the header view sits on top of the table, but my header view scrolls just like a normal row. Is there a way to make the header view always visible at the top of the table?
You certainly did found the solution for this, but I'm posting it here for other people.
The table view header and footer views do scroll with the rest of the rows.
If you want them to have a fixed position on top, or bottom of the table view then you don't really need a header or footer view.
Just add your desired view as a sibling of the table view (subview of tableView's superView) and position it on top or bottom of the tableView.
The solution is to implement:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
and
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
for a fixed header view, not use the self.tableView.tableHeaderView (this one is scrollable).

Look like iPhone inbuilt contact applications image selection

I have created an application in which i have to add users to the sqlite database.
Now the problem is I want the look of the standard iPhone Contact application Where while adding user we have the width of first cell smaller than other cells and the image before that cell..
Can you please give me the idea how such thing is possible.
How to make one cell small and rest others of normal size..
Thanks for any help in advance
There are three UITableViewDelegate messages you can listen for to adjust height
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
However, even thought I didn't write Contacts.app I have a feeling they are also using
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
To adjust the views as well. Remember, you don't have to pack everything into a single monolithic custom table view cell. You can create multiple custom table view cells and load them each appropriately depending on the index path.
The contact detail view is a grouped tableview. Each cluster of cells is a section. The top section is a single custom cell with two subviews that look like squashed tableview cells. The left view shows the contact's photo. The right view shows the name.
To reproduce, create a custom UITableView subclass and lay it out like you want either programmatically or in Interface Builder. Then in the tableview delegate's cellForRowAtIndexPath check indexPath.section and return the proper row for the section.
It appears that the Contacts app uses a custom tableHeaderView when presenting the contact details with an image and label. A similar implementation is included in the sample project iPhoneCoreDataRecipes. The RecipeDetailView loads a separate nib in tableViewHeaderView that is used to set the tableView.tableHeaderView property. Have a look at RecipeDetailViewController.{h,m} and DetailHeaderView.xib. When the Contacts app switches to editing mode, the headerView appears to be swapped out for another view that has a button and a tableView with a single cell. This will allow you to set up a separate tableViewDelegate to handle the Name parts of the contact and a delegate to handle the address / telephony details.