我的ViewController里面有一个tableView,每次我尝试reloadData或点击单元格。一个特定的标签移动得更高并保持不变。
在重新加载或点击之前!:
reloadData或单击一个单元格后:
任何想法出了什么问题?
我调用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中,(我出于另一个原因使用两个数组)并使用此数组填充表,如下所示:
- (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',因为它是'readwrite',但它将通过另一个属性'readonly'合成。”
答案 0 :(得分:1)
由于我注意到的通知,我找到了解决方案!
我只需要添加:
@synthesize textLabel in the WorkCell.m file