How to design a tableview similar contact application in iphone.........
you want the delegate method:
- (UIView)tableView:(UITableView *)tableView viewForHeaderAtSection:(NSInteger)section;
construct and return a UIView in that method.
Most likely they use UITableView with grouped style and custom views for table header and footer. (see tableFooterView and tableHeaderView properties)
Related
I have used storyboard to design a grouped tableView with simple, static content. I want to change the look of the section headers, but storyboard does not seem to offer this functionality, and I cannot determine how to get programmatic access to the section headers without building the interface from code.
For reference, the following SO question fully resolves the problem in the case that the dataSource is dynamic.
How to change text color for Section Headers in a Grouped TableView in iPhone SDK?
Is a similar solution possible where the content is STATIC and I am NOT implementing the UITableViewDataSource protocol?
Here's an alternative approach. It will change the font size of ALL table headers and footers, which is one potential drawback, but it is simpler than the approach above I think
[[UILabel appearanceWhenContainedIn:[UITableViewHeaderFooterView class],nil] setFont:[UIFont systemFontOfSize:24.0f]];
If I remember correctly, you can click on a UIView object and drag it to the top of your table view in storyboard, and it will serve as it's header:
Otherwise, many of the tableview's delegate (not datasource) methods are still available even for static table views. So the delegate method:
-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Will still be called. In here you can create a customized view to return as the header. This UIView can be created programmatically or in a .xib or storyboard view controller (via UIViewController.view).
Edit 1:
The drag and drop is for the UITableView's header, not the section. However, the method above will return a custom view for each section's header.
You can not do this via Storyboard and static cell, only table header, table footer, cells can use your custom views.
I am coding an iPhone App in which am using a UITableView which has several sections ; each section has a header & then its rows like this:
I can do the row styles correctly, by using custom UITableViewCell objects, but how do I do the header? As you can see:
the header has the text centered with two lines drawn from it, one on each side
The header color is different
also the corners of each section are rounded
how do I achieve this, either programmatically or using Storyboard?
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
This method, implemented as part of your UITableViewDelegate, is intended to allow you to to create custom views for headers in UITableViews. You can return any UIView from that method, whether it's one that you want to create in Interface Builder, or in code.
I am using the xcode template to create a UITableView application with UINavigationController.
I need to add a UIView (at fixed position) between the UINavigationBar and the UITableView. How to do that ?
Thanks.
You can do this by setting the UITableView's tableHeaderView property.
UITableView class reference
tableHeaderView
Returns an accessory view that is displayed above the table.
#property(nonatomic, retain) UIView *tableHeaderView
Discussion The default value is nil. The table header view is
different from a section header.
Availability Available in iOS 2.0 and later.
Add UIView and UITableView as subviews of UIView and then position their height, width and x, y position from the Size Inspector in Interface builder or Use CGRectMake in objective-c
you need to implement following UITableview delegate methods
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
Step 1)
Create a header view as, set outlet to that view.
#property(nonatomic,strong)IBOutlet UIView *viewHeader;
Setp 2)
Add following single line code on viewDidLoad
[self.tableview setTableHeaderView:self.viewHeader];
Done!!!
Views are maintained in a hierarchy in iOS. They are maintained essentially as an array with the latest view first. To insert some view below one view or above another you just need to manipulate this.
All this is theory, I have not done what you want. So dont hold a grudge against me ;) this is a friendly suggestion.
[self.view insertSubview:yourNewView belowSubview:navigationController];
I added UISearchBar as tableHeaderView for UITableView in xib, by just dropping UISearchBar onto UITableView.
It is working fine, when the table has more than 6 rows.
But when there is less than 6 rows, it UITableView does not scroll.
At the same time, if i add the UISearchBar as tableHeaderView for UITableView programatically in .m file using the following statement, EVERYTHING WORKS FINE.
tableViewTemp.tableHeaderView = searchBarFriends;
Seems very strange to me,
What might be the problem?
Please advice, Thank you.
Here is a little trick I did ;) Don't make your SearchBar a subview of your UITableView. Just add instances of them both in your nib file and wire them up as IBOutlets in your UITableViewController. Then what you are going to do is set the SearchBar as the header view for your table, that way you don't have to worry about the frames overlapping and interfering with touch events. Here's how you do it:
Create the property in your TableView header file
#property ( nonatomic, retain ) IBOutlet UISearchBar *searchBar;
Set the header view for your table:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return self.searchBar; // The property you wired up in IB
}
Set the height for your header or (UISearchBar)
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 44; // The height of the search bar
}
That's all you need. Now this may not be the best solution if you have a grouped tableview or a table with multiple sections but its a clean solution for a simple table. Otherwise, you'd have to adjust the frame of the searchbar AND the tableview in code because they overlap and thats why you have touch issues. Hope this helps!
if you add search bar like below hierarchy it will work
I had almost the same problem (for me it wouldn't scroll at all with any number of rows, but it would as soon as I removed the search bar). Fixed it adding this in viewDidLoad:
self.tableView.alwaysBounceVertical = YES;
In RootViewController am using a UITableView for displaying the content of data. In the didSelectRowAtIndexPath method, I am calling another view controller (DetailViewController) to display detailed data. For displaying this detailed data I am using a UITableview in the DetailViewController also. This table contains one section and only one row.
Now the problem is that I have to adjust the table's height dynamically when I move from RootViewController to DetailViewController. How can I make the height of the UITableView dynamic between the two classes?
Any help would be Appreciated!
You can implement the UITableViewDelegate method something like:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [TextToDisplay sizeWithFont:/*DESIRED_FONT*/ constrainedToSize:/*YOUR DESIRED_SIZE*/ lineBreakMode:/*DESIRED_LINEBREAKMODE*/].height;
}
to get variable heights.
It sounds like your trying to reuse a UITableView between two different UIViewControllers. I think your better off having the RootViewController have it's own UITableView which is set to a dynamic height and width using the UIView autoresizingMask property. Then when you select a row and push on the DetailViewController in a UINavigationController stack it would have it'd own UITableView to display the detail information your trying to show.
This interaction technique is used throughout other iPhone applications like Mail. If I misunderstood your question please let me know.