2013-08-29 119 views

回答

3

当然,只是使细胞的一个子类,并添加你的字典。你可以使用一个完全空的实现,以及:

// MyCell.h 
@interface MyCell : UITableViewCell 

@property (nonatomic, strong) NSDictionary* dictionary; 

@end 

// MyCell.m 
@implementation MyCell 
@end 

现在,只要确定你设置你的类,如果您使用的是故事板,或者如果你不进行注册,然后只需设置词典当你将它取出并在稍后返回时读取它。

+0

很好..要弄清楚如何现在子类化..非常感谢你。 – HurkNburkS

2

如果您在自定义单元格中创建UITableViewCell子类并创建NSDictionary属性,则可以实现此目的。

假设你已经设置该属性在什么地方,在这里是如何获得它被选中单元格时:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    MyCustomCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    NSLog(@"%@",cell.dictionary); //replace "dictionary" by the name of the property you created in the subclass 
} 
1

您应该努力从视图(MyCell)中分离数据模型(NSDictionary)。这就是视图控制器的用途 - 管理每个单元格和数据之间的关系。

你的数据模型通常是一个NSArray。数组中的每个元素对应于表中的一行(indexPath)。每个NSArray元素都会为每个单元格保存一个NSDictionary对象(数据模型)。