在UITableView中滚动后数据丢失
我试图在tableview中显示plist数据在UITableView中滚动后数据丢失,uitableview,ios6,plist,Uitableview,Ios6,Plist,我试图在tableview中显示plist数据 tableData = [[NSArray arrayWithObjects:[dic objectForKey:@"Response"], nil] retain]; 我的问题是,向下滚动后,我丢失了以前获取的数据。 事实上,我正在使用自定义单元格,所以我认为这是可能的 下表的源代码和委托代码 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSIn
tableData = [[NSArray arrayWithObjects:[dic objectForKey:@"Response"], nil] retain];
我的问题是,向下滚动后,我丢失了以前获取的数据。
事实上,我正在使用自定义单元格,所以我认为这是可能的
下表的源代码和委托代码
- (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];
}
你为每个单元设置了高度吗
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGFloat height = 0;
//calculate height for each cell
return height;
}
使用此UITableView委托方法设置单元格高度。您可以使用另一个类来存储数据,并在使用该类时重新加载数据,并正确有效地恢复数据 我解决了它。:) 唯一的问题是没有为UItableview保留内存
tableData = [[NSArray arrayWithObjects:[dic objectForKey:@"Response"], nil] retain];