Add image and caption text to the Three20 section using TTSectionedDataSource

I am trying to create a table using TTTableViewController . I want to display an image in the section title along with the signature text, something similar to what instagram and many other applications do. I tried using a sample from TTNavigatorDemo to display data from TTSectionedDatasource (I'm not sure if this is the right way to do this, please suggest a better way if you know any). It contains section headings / headings like regular rows and data like TTTableViewItem . I tried to implement the <UITableViewDelegate> protocol and reached it using the viewForHeaderInSection method, now the data is separated from the section, is there a better way using Three20 through which I can pass my header / section and TableItemView along the data source, as this would allow me implement TTTableViewDragRefreshDelegate , which I could not implement when implementing the <UITableViewDelegate> protocol in my class.

My class declaration right now looks something like this:

 @interface ImageTable : TTTableViewController <UITableViewDelegate> { } 

I would like to show section headings with image and text, for example:

Instagram :

I am currently using TTNavigatorCode to populate data in my table, which:

  self.dataSource = [TTSectionedDataSource dataSourceWithObjects: @"Food" [TTTableViewItem itemWithText:@"Porridge" URL:@"tt://food/porridge"], [TTTableTextItem itemWithText:@"Bacon & Eggs" URL:@"tt://food/baconeggs"], [TTTableTextItem itemWithText:@"French Toast" URL:@"tt://food/frenchtoast"], @"Drinks", [TTTableTextItem itemWithText:@"Coffee" URL:@"tt://food/coffee"], [TTTableTextItem itemWithText:@"Orange Juice" URL:@"tt://food/oj"], @"Other", [TTTableTextItem itemWithText:@"Just Desserts" URL:@"tt://menu/4"], [TTTableTextItem itemWithText:@"Complaints" URL:@"tt://about/complaints"], @"Other", [TTTableTextItem itemWithText:@"Just Desserts" URL:@"tt://menu/4"], [TTTableTextItem itemWithText:@"Complaints" URL:@"tt://about/complaints"], nil]; 

I was able to do something similar by implementing a method:

 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { return myCustomView; } 

But since my data comes from the model class, and I want my generating views to add it to the data source in a formatted way. I would like to know if there is a way to use Three20 through which I specify an array of my data for partitions and another array for the corresponding data for partitions?

Your help is much appreciated

thanks

+4
source share
1 answer

Create Delegate FOOTableDelegate.h

 @interface FOOTableDelegate : TTTableViewDragRefreshDelegate { } - (UIView*) createHeaderView:(FOODataSource *)fDataSource forSectionID:(NSString *)secID; @end 

In the file FOOTableDelegate.m

 - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if (tableView.style == UITableViewStylePlain) { if ([tableView.dataSource respondsToSelector:@selector(tableView:titleForHeaderInSection:)]) { NSString* title = [tableView.dataSource tableView:tableView titleForHeaderInSection:section]; if (title.length > 0) { UIView* header = [_headers objectForKey:title]; if (nil != header) { header.alpha = 1; } else { if (nil == _headers) { _headers = [[NSMutableDictionary alloc] init]; } header = [self createHeaderView:tableView.dataSource forSectionID:title]; [_headers setObject:header forKey:title]; } return header; } } } return nil; } - (UIView*) createHeaderView:(FeedDataSource *)fDataSource forSectionID:(NSString *)secID { //do some code for header View return View; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { //return height for the Section Header return height; } 

This will help you solve your problem.

+1
source

Source: https://habr.com/ru/post/1340242/


All Articles