Reputation: 2265
I have a tableView inside my ViewController and every time i try to reloadData or click the cell. A specific label moves higher and stays there.
Before reload or click!:
After reloadData or click a cell:
Any ideas what is going wrong?
I call read function to get all the data in the database and store them in the 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];
});
}
}];
});
I copy this array into another NSArray, ( i use two arrays for another reason) and use this array to populate the table as follows:
- (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];
}
}
and then every time I call reloadData it comes to the same result either i have changed the siteTableObjectsFinalArray or not!
After digging in the code i found a notification in WorkCell.h: "Auto property synthesis will not synthesize property 'textLabel' because it is 'readwrite' but it will be synthesized 'readonly' via another property."
Upvotes: 0
Views: 341
Reputation: 2265
I found out the solution thanks to the notification i noticed!
I just had to add:
@synthesize textLabel in the WorkCell.m file
Upvotes: 1