2013-02-13 31 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

您可以使用另一個存儲數據的類,並重新載入使用該類的時間並正確有效地還原數據。