Custom Section Title View for UITableView - iphone

In some apps such as Cool Iris, LiveShare, i see them using custom views for their plain UITableView section titles. Is there a way to replace the standard section title bar with a custom view?

In order to customize the look of your section header, there are two methods you will probably want to use.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
and
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
These are both found in the UITableView delegate protocol. The first will let you create a custom view to display as your section header. The second just makes sure you get the size you want for it so that your view doesn't get cut off

Related

Displaying both section header and custom view for table section header

I have a table view with multiple sections. I want to display different section header titles and want to add a label on the right corner of each section at a right margin of 4px.
Can I implement both
- (NSString *)tableView:(UITableView *)iTableView titleForHeaderInSection:(NSInteger)iSection
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
to achieve this?
Only one of them will ever get called successfully. tableView:viewForHeaderInSection: will get precedence.
Define a view with a title label and another label that sits on the right corner and return it in tableView:viewForHeaderInSection: with the values set.

UITableView Implementation

in the screen shot below, there are UISegmentedControl in between grouped UITableViewCells...it seems. How does one add other controls in between grouped cells in a UITableView?
You could make the Segmented View the same size as 1 table cell. Dead Simple to do in Interface Builder.
Tables with multiple sections, and sections can have custom header and footer..
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section; // custom view for header. will be adjusted to default or specified header height
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section; // custom view for footer. will be adjusted to default

Custom View in UITableViewCell

I am trying to create a UITableView Section that contains two buttons aligned horizontally. This would be similar to the Contacts app, where on the bottom of a specific contact page they have buttons lined up to Text the contact and share the contact. However in my tableView, I want the two buttons to be placed in between other sections - so i can't set the table's header or footer view? How would i do this?
If I understand the question correct, you want something like this
section 1
your buttons
section 2
For this you can create custom headers/footers for sections instead of table. The methods you might be looking for are in UITableViewDelegate
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Look into subclassing UITableviewCell class, you can draw your custom view in there and use it, look at the UICatalog sample project in Apple site they do that there a lot

Displaying a UITableView followed by an image, followed by more UITableViewCells

I've seen some applications on the iPhone have an image on top of the tableView, which is straight forward and can be set with something like tableViewHeader.. and a picture below set with tableViewFooter. I recently seen an application where there is an image in the header, a table view, then another image below the footer, and then subsequently a couple UITableViewCells...
Is there a straight forward way to accomplish this without using two UITableViews in the same controller?
Multiple sections will accomplish this, you can also use this method on your UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
in conjunction with a custom UITableView cell created in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
This will allow you to specify a custom cell with the appropriate height that contains your image.
Use 2 sections.

[iPhone]How to customize header of Section in grouped TableView?

To customize cell, we implement class inherit UITableViewCell. Now, to customize header of Section in grouped UITableView (same to below picture), how to do? Please guide to me!
Implement tableView:viewForHeaderInSection: in your table view delegate.
Starting with iOS 5 you also need to implement
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
In addition to
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Otherwise it won't work.
From Apple's reference
The returned object can be a UILabel or UIImageView object, as well as a custom view. This method only works correctly when tableView:heightForHeaderInSection: is also implemented.