2013-02-13 40 views
0

我想在tableview中显示plist数据。滚动后在UITableView中丢失的数据

我的问题是,滚动后我失去了我以前提取的数据。 其实我正在使用自定义单元格,所以我认为这是发生。

表的源和代表的代码如下。

- (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]; 
} 

回答

0

我解决了它。 :)

唯一的问题是没有为UItableview保留内存。

tableData = [[NSArray arrayWithObjects:[dic objectForKey:@"Response"], nil] retain]; 
0

你有没有设置高度为每个小区

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 

    CGFloat height = 0; 
    //calculate height for each cell 

    return height; 
} 

使用此的UITableView委托方法来设置细胞的高度。

0

您可以使用另一个存储数据的类,并重新载入使用该类的时间并正确有效地还原数据。