Creating a UITableView with Taller Cells on the iPhone - iphone

How can I go about creating a UITableView with taller cells? Basically, I want to create a full screen table with only four cells, but they should take up the entire screen (1/4 each).
Assuming this is possible using a UITableView, can it be done both in code and in Interface Builder? And also, can each cell have its own height?
--Tim

Just use the -tableView:heightForRowAtIndexPath: method from the UITableViewDelegate protocol to customize the height of each cell. Something like this works just fine:
- (CGFloat)tableView:(UITableView *)tv heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 70.0f;
}
Hope that helps.

For best performance, if all your rows are the same height, use the rowHeight property. It's accessible from both code and Interface Builder.
If you want to customise individual row heights, then you need to implement the - tableView:heightForRowAtIndexPath: delegate method. It's a little slower performing, but more flexible.

Related

UITableView weird padding at the bottom of cell

I have a UITableView in which I am displaying bunch of custom cells. The cell is configured to be 50 pixels in height:
I am retuning 50 in the heightForRow method:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 50.f
}
But in the end, there's a weird 10-15ish pixel padding/spacing between each cell:
What am i doing wrong?
Thanks!
Without seeing your custom cell's configuration code, I can only guess. The space you see is likely internal to the cell. Perhaps you've added a green subview, but it isn't sized to fit the cell. You probably need to set the subview to have a flexible height (or if you're using Auto Layout, pin the top and bottom to the parent).
Or maybe you have one cell per section and you're somehow creating a blank header or footer.

Set Cell Subview Position After Height Set?

In my app I have a tableview, with a custom tableviewcell and that has a UIImageView in it.
However, my issue. - (void)configureCell:(MyCustomCell *)cell atIndexPath:(NSIndexPath *)indexPathwhere I set the frame of my image is called before - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath where I set the cell height.
Meaning, the image position isn't correct (its dynamic, changes depending on cell height).
How do you suggest I get around this?
Thanks.
When do you call your configureCell:atIndexPath: method? In your tableView:cellForRowAtIndexPath: implementation?
Anyway, try to set you image height in tableView:willDisplayCell: delegate method instead. This method is called just bore the cell is displayed on screen so that it will not be resized afterwards by other internal methods.
Besides, can't you use the AutoresizingMask property to make your image view resize automatically depending on its container view (the cell)?

iPhone UIViewController Lag

I have a 'detail' page where I am displaying info for a club. The page is a UIViewController and consists of buttons and labels to acheive this look (like small grouped tables). When I load this page on a device, it lags a bit, more than any other view in my app.
I assume its because I have quite a few objects on the view controller. Does anyone have any suggestions on how to reduce this lag? Or how to achieve the look the 3 smaller tables like this(grouped) in a different way?
Thanks.
SCREENSHOT:
You could try making custom tablecells and use UITableView instead?
You could just make the view a UITableView using UITableViewStyleGrouped style, and then programmatically create the cells for each row. Overriding
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
gets you your titles like "Meeting Information" and "Contact", and overriding
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
gets you correct sizing on each table cell. If the text in "General Information" is not going to be a constant size, you can use the
-sizeWithFont::(UIFont *)font
method of NSString in your heightForRowAtIndexPath implementation.
The issue is not likely your interface design. UI drawing is pretty snappy usually. The things that slow it down are accessing data. If you have a large data set you are searching you might look at ways to speed that up.

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.

Relative Height of UITableview

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.