我想知道是否有一种方法可以将NSDictionary
对象附加到在UITableView
中显示的单元格上,以便当选中一个单元格时,我可以访问附加到该tableviewcell上的NSDictionary
。
我想知道是否有一种方法可以将NSDictionary
对象附加到在UITableView
中显示的单元格上,以便当选中一个单元格时,我可以访问附加到该tableviewcell上的NSDictionary
。
// MyCell.h
@interface MyCell : UITableViewCell
@property (nonatomic, strong) NSDictionary* dictionary;
@end
// MyCell.m
@implementation MyCell
@end
如果您使用子类化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
}