Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added an initialization block to ab_reusableCellOfClass:identifier: and a new macro to use it #33

Merged
merged 1 commit into from

2 participants

@joshaber
Collaborator

For one-time setup when the cell is first created

@joshaber joshaber added an initialization block to ab_reusableCellOfClass:identifier: a…
…nd a new macro reusableTableCellOfClassWithBlock

for one-time setup when the cell is first created
f0feadf
@atebits

love it

@atebits atebits merged commit 82a8268 into twitter:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 3, 2011
  1. @joshaber

    added an initialization block to ab_reusableCellOfClass:identifier: a…

    joshaber authored
    …nd a new macro reusableTableCellOfClassWithBlock
    
    for one-time setup when the cell is first created
This page is out of date. Refresh to see the latest.
View
9 lib/UIKit/TUITableView+Additions.h
@@ -16,11 +16,16 @@
#import "TUITableView.h"
+typedef void (^TUITableViewInitializationBlock)(id cell);
+
@interface TUITableView (Additions)
-- (TUITableViewCell *)ab_reusableCellOfClass:(Class)cellClass identifier:(NSString *)identifier;
+- (TUITableViewCell *)ab_reusableCellOfClass:(Class)cellClass identifier:(NSString *)identifier initializationBlock:(TUITableViewInitializationBlock)block;
@end
+#define reusableTableCellOfClassWithBlock(TABLE, CLASS, BLOCK) \
+ (CLASS *)[(TABLE) ab_reusableCellOfClass:[CLASS class] identifier:@"ab." @#CLASS initializationBlock:BLOCK]
+
#define reusableTableCellOfClass(TABLE, CLASS) \
- (CLASS *)[(TABLE) ab_reusableCellOfClass:[CLASS class] identifier:@"ab." @#CLASS]
+(CLASS *)[(TABLE) ab_reusableCellOfClass:[CLASS class] identifier:@"ab." @#CLASS initializationBlock:nil]
View
6 lib/UIKit/TUITableView+Additions.m
@@ -18,11 +18,13 @@
@implementation TUITableView (Additions)
-- (TUITableViewCell *)ab_reusableCellOfClass:(Class)cellClass identifier:(NSString *)identifier
+- (TUITableViewCell *)ab_reusableCellOfClass:(Class)cellClass identifier:(NSString *)identifier initializationBlock:(TUITableViewInitializationBlock)block
{
TUITableViewCell *cell = [self dequeueReusableCellWithIdentifier:identifier];
- if(!cell)
+ if(!cell) {
cell = [[[cellClass alloc] initWithStyle:TUITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
+ if(block != nil) block(cell);
+ }
return cell;
}
Something went wrong with that request. Please try again.