Skip to content

Commit e25bb1d

Browse files
committed
Add section title block
1 parent 1658474 commit e25bb1d

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

Demo/TableDemo/PEPhotosDetailViewController.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ - (AMBTableViewSection *)commentsSection
188188
}
189189
}];
190190

191+
// Enable section title
192+
_commentsSection.sectionTitleBlock = ^NSString *(AMBTableViewSection * section)
193+
{
194+
return @"Comments";
195+
};
196+
191197
// Enable "no content cell"
192198
_commentsSection.presentsNoContentCell = YES;
193199
}

Source/AMBTableViewController.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@
125125

126126
/// @name AMBTableViewSection Blocks
127127

128+
/// A block used to return the name of the section.
129+
/// @param section The section that whose title to return.
130+
/// @return String to be used for the title of the section
131+
typedef NSString * (^AMBTableViewSectionTitleBlock)(AMBTableViewSection * section);
132+
128133
/// A block where any aspect of the section can be changed and rows can set to be shown/hidden,
129134
/// reloaded, etc.
130135
/// @param The section to be updated.
@@ -204,6 +209,9 @@ typedef void (^AMBTableViewCellConfigurationBlock)(id object,
204209
/// The AMBTableViewController assigned when the section is added to [AMBTableViewController sections].
205210
@property (weak, nonatomic) AMBTableViewController * controller;
206211

212+
/// An optional block to be called on [UITableView tableView:titleForHeaderInSection:].
213+
@property (copy, nonatomic) AMBTableViewSectionTitleBlock sectionTitleBlock;
214+
207215
/// An optinal block to be called on update on [AMBTableViewController updateAllSections] calls.
208216
@property (copy, nonatomic) AMBTableViewSectionUpdateBlock sectionUpdateBlock;
209217

Source/AMBTableViewController.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,16 @@ - (CGFloat)tableView:(UITableView *)tableView
329329
return self.tableView.rowHeight;
330330
}
331331

332+
- (NSString *)tableView:(UITableView *)tableView
333+
titleForHeaderInSection:(NSInteger)sectionIndex
334+
{
335+
AMBTableViewSection * section = self.sections[sectionIndex];
336+
if (section.sectionTitleBlock) {
337+
return section.sectionTitleBlock(section);
338+
}
339+
return nil;
340+
}
341+
332342
@end
333343

334344

0 commit comments

Comments
 (0)