2014-04-14 64 views
0

我的ViewController中有一個tableView,每當我嘗試重新裝入數據或單擊單元格時。一個特定的標籤移動更高並停留在那裏。TableViewCell的UILabel更改reloadData上的位置onClick

之前重裝或點擊!:

reloadData後或單擊單元格: enter image description here

任何想法是什麼問題呢?

我調用read函數來獲取數據庫中的所有數據,並將它們存儲在NSMutableArray siteTableObjectsArray中。

dispatch_async(backgroundQueue, ^(void){ 
    [self read:^(BOOL finished) { 
     if(finished){ 
      dispatch_async(dispatch_get_main_queue(), ^{ 
       siteTableObjectsFinalArray = [siteTableObjectsArray copy]; 
       NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] 
                initWithKey:@"work.title" ascending:YES]; 
       NSArray *sortDescriptors = [NSArray arrayWithObject: sortDescriptor]; 
       siteTableObjectsFinalArray = [siteTableObjectsFinalArray sortedArrayUsingDescriptors:sortDescriptors]; 
       [self.tableView reloadData]; 
      }); 

     } 
    }]; 
}); 

我複製此陣列到另一個的NSArray中,(i使用兩個陣列的另一個原因),並使用此陣列來填充該表,如下所示:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
WorkCell *cell = (WorkCell *) [tableView dequeueReusableCellWithIdentifier:@"WorkCell"]; 

SiteTableObject *obj = [siteTableObjectsFinalArray objectAtIndex:indexPath.row]; 
Authors *currAuth = obj.author; 
Works *currentWork = obj.work; 

cell.authorLabel.text = currAuth.authorName; 
cell.workLabel.text = currentWork.title; 
NSString* cleanedString = [obj.text stringByTrimmingCharactersInSet: [NSCharacterSet symbolCharacterSet]]; 
cell.textLabel.text = cleanedString; 


cell.caategoryLabel.text = [categoriesDictionary objectForKey:[NSString stringWithFormat:@"%@",currentWork.categoryID]]; 
cell.dateLabel.text = [NSString stringWithFormat:@"%@", currentWork.date]; 
cell.moreLabel.text = [NSString stringWithFormat:@"%i more",obj.more]; 
return cell; 

}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ 
cell.backgroundColor = [UIColor clearColor]; 

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
WorkCell *cell = (WorkCell *) [tableView cellForRowAtIndexPath:indexPath]; 
currentIndexRow =indexPath.row; 
SiteTableObject *clickedObject = [siteTableObjectsFinalArray objectAtIndex:indexPath.row]; 
Works *clickedWork = clickedObject.work; 
selectedWorkId = [clickedWork.workID intValue]; 
if ([cell.moreLabel.text isEqualToString:@"0 more"]) { 
    [self performSegueWithIdentifier:@"p" sender:self]; 
}else{ 
    [self performSegueWithIdentifier:@"more" sender:self]; 
} 

}

然後每次我調用reloadData時,都會得到相同的結果,或者我已經更改了siteTableObjectsFinalArray!

在挖掘代碼後,我在WorkCell.h中發現了一條通知: 「自動屬性綜合不會合成屬性'textLabel',因爲它是'讀取',但它將通過另一個屬性'只讀'合成。

+0

什麼是你的代碼? – Larme

+1

如果你正在使用故事板或xib文件,你應該檢查你的約束。您還應該添加更多與您的自定義單元格相關的代碼。 – Szu

+0

好吧,我添加了我的代碼! – arniotaki

回答

1

感謝我注意到的通知,我找到了解決方案!

我不得不補充:

@synthesize textLabel in the WorkCell.m file