Reputation: 5883
I want a table view like this
What i understood is that they are using static cells other than where to display call details.How to make a tableview like the above one(where dynamic cells are kept between static cells).I went through lot of stuff like this How to implement UITableView With Static and Dynamic Cells -- IOS,this was the best of all,but was not able to find a solution.Any tutorials or advice would be appreciated.I'm still in pursuit of achieving this.
Upvotes: 4
Views: 1986
Reputation: 2859
I don't think this is difficult to do.
Using -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
to return the height of cell for each row. Example in my code:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyAddress *address = self.dataSource[indexPath.row];
return [MyAddressCell cellHeightForAddress:address];
}
Inside - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
, fill the data into your cell:
MyAddress *address = self.dataSource[indexPath.row];
[cell fillWithAddress:address];
Upvotes: 2
Reputation: 13511
I'll suggest a couple of approaches:
The easier way is to create a different UITableViewController
for every possible combination of static and dynamic table view cells there may ever be in your app. This means that the Contacts app above will have one UITableViewController
when there are no call logs for the user being displayed, and another one when there already are. There are downsides to this approach: a) If you are in the table view controller with call logs and the logs are cleared, switching to the log-less one may be difficult; b) If you're using storyboards, copy-pasting a prototype cell across many view controllers can also be difficult. I'm sure there are more, but for some screens with simple functionality (ones that aren't forms), the ease of building it this way outweighs the disadvantages.
Consider your screen as a static UITableView
with dynamically resizing UIView
s inside. For example, the above contacts app will be a table view with 4 rows: the mugshot AND call logs, the home number, Facetime, and Notes. The mugshot and call logs are in a single custom UIView
in a single UITableViewCell
. If there are no call logs for the user being displayed, the custom UIView
only displays the mugshot, but if there are, it also displays the call logs.
In short, the numberOfRowsInSection:
is constant--the UIView
s inside the UITableViewCell
s are not. If a row dynamically appears or disappears, put it in the same row as the one above it, just make sure to compute for the cell's height in heightForRowAtIndexPath:
depending on whether the dynamic component should be shown or not.
Upvotes: 0