我正在尝试在 tableview 中显示 plist 数据。
我的问题是,向下滚动后,我丢失了以前获取的数据。实际上我正在使用自定义单元格,所以我认为这是发生的。
表的源代码和委托代码如下。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *kCellID = @"Cell";
OffersCustomCell *cell = (OffersCustomCell *)[mytableView dequeueReusableCellWithIdentifier:kCellID];
if (cell == nil)
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"OffersList" ofType:@"plist"];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"OffersCustomCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.titleLabel.font = [UIFont fontWithName:@"Formata-Regular" size:13.0f];
cell.saveLabel.font = [UIFont fontWithName:@"Formata-Bold" size:14.0f];
cell.nowLabel.font = cell.titleLabel.font;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
NSDictionary *dict = [tableData objectAtIndex:indexPath.row];
NSLog(@"%@",dict);
cell.titleLabel.text = [dict objectForKey:@"title"];
cell.nowLabel.text = [dict objectForKey:@"price"];
cell.saveLabel.text = [dict objectForKey:@"rondel"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[mytableView deselectRowAtIndexPath:indexPath animated:YES];
}