此加载的UITableViewCell特殊的方式是一种方法,我发明了从笔尖
1)我用我的UITableViewCell类,扩展
//.h
@interface UITableViewCell (Extended)
+ (id) cellWithClass:(Class)class;
+ (id) cellWithClass:(Class)class fromNibNamed:(NSString *)nibName;
@end
//.m
+ (id) cellWithClass:(Class)class
{
return [UITableViewCell cellWithClass:class fromNibNamed:NSStringFromClass(class)];
}
+ (id) cellWithClass:(Class)class fromNibNamed:(NSString *)nibName {
NSArray * nibContents = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:NULL];
NSEnumerator * nibEnumerator = [nibContents objectEnumerator];
NSObject * nibItem = nil;
while ((nibItem = [nibEnumerator nextObject]) != nil) {
if ([nibItem isKindOfClass:class]) {
return nibItem;
}
}
return nil;
}
2)创建自定义的UITableViewCell子类加载定制单元,用笔尖相同的名称(CustomCell.xib)其中,i都出口连接
@interface CustomCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel * labelSmth;
- (void) setupWithTitle:(NSString *)title;
@end
2)在CustomCell.xib使用界面生成器i的拖动一个UITableViewCell并使其类CustomCell(重用标识符CustomCell)(我不设置文件所有者)...比做UI风格,连接插座等..
3)比装载方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * identifier = @"CustomCell";
CustomCell * cell = [self.tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [UITableViewCell cellWithClass:[CustomCell class]];
}
[CustomCell setupWithTitle:[self.titles objectAtIndex:[indexPath row]]];
return cell;
}
* 这种方法行吗?这工作了很多项目,但IAM不知道的reuseidentfier和大约如果细胞被正确重用的事实... *
IAM还不能确定这个
NSArray * nibContents = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:NULL];
因为我通过业主自治在一个类的方法...
也是苹果已经想出了
- (void) registerNib:(UINib *)nib forCellReuseIdentifier:(NSString *)reuse;
这怎么可能适合我的方法呢?
以及如何使用自定义的重用标识符,就像如果我想的方法
+ (id) cellWithClass:(Class)class fromNibNamed:(NSString *)nibName reuseIdentifier:(NSString *)reuseIdentifier;
请问你的样品得到的影响与新的 - (空)registerNib:(UINib *)笔尖forCellReuseIdentifier:(的NSString *)再利用; ? – 2012-07-23 08:45:19
如何使cellIdentifier为NIB?这不会起作用! – applefreak 2014-01-15 15:28:15
你是什么意思? @applefreak – bandejapaisa 2014-01-20 16:21:54