Hey, My app is coming along but I hit a snag with number overlapping on a UILabel. I included 2 photos and you can see on one the number 2 in the green dot looks clear, but in the other is is a blend of 2 numbers.
I click on the TableView row, it opens a new ViewController where I add a new job which increments the count to 3 and write the result to a property list. I then navigate back to the the first viewController and reload the data from the Property list. But now instead of the number 3 it is a blend of the numbers 2 and 3 as you can see in the photo.
When I launch the program everything loads and displays just fine, it's only when I make a change. I think my problem area is in the TableView cellForRowAtIndexPath:. This is where it loads the data and sets up the cells.
I click on the TableView row, it opens a new ViewController where I add a new job which increments the count to 3 and write the result to a property list. I then navigate back to the the first viewController and reload the data from the Property list. But now instead of the number 3 it is a blend of the numbers 2 and 3 as you can see in the photo.
When I launch the program everything loads and displays just fine, it's only when I make a change. I think my problem area is in the TableView cellForRowAtIndexPath:. This is where it loads the data and sets up the cells.
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NSDictionary *tempDict = [[NSDictionary alloc] initWithDictionary:[clientListForTable objectAtIndex:indexPath.row]];
NSLog(@"Temp Dict has %@", tempDict);
cell.textLabel.text = [tempDict objectForKey:@"client"];
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:18.0];
cell.textLabel.font = [UIFont boldSystemFontOfSize:16.0];
cell.textLabel.textColor = [UIColor whiteColor];
cell.detailTextLabel.text = [tempDict objectForKey:@"businessName"];
cell.detailTextLabel.textColor = [UIColor whiteColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
NSString *jobNum = [NSString stringWithFormat:@"%@",[tempDict objectForKey:@"numberOfJobs"]]; //NSNumbers convert to NSString
if (![jobNum isEqualToString:@"0"]) { //First check to see if there are jobs in the array
CGRect boxRect = CGRectMake(0, 0, 44, 44);
UIImage *newImage = [UIImage imageNamed:@"greenSquare.png"]; //load the image
UILabel *numLabel = [[UILabel alloc] initWithFrame:boxRect]; //create the Label
NSLog(@"UILabel: %@", jobNum); //test wha tthe UILabel number should be
numLabel.text = jobNum;
numLabel.textColor = [UIColor blackColor];
numLabel.backgroundColor = [UIColor clearColor];
numLabel.textAlignment = UITextAlignmentCenter;
numLabel.font = [UIFont boldSystemFontOfSize:15.0];
cell.imageView.image = newImage; // adds the green square png to the view
cell.imageView.layer.masksToBounds = YES;
cell.imageView.layer.cornerRadius = 20.0;
[numLabel removeFromSuperview]; //Removes the UILabel from the view, trying to fix problem
[cell.imageView addSubview:numLabel]; // adds the UILabel back with the new number
}
return cell;
}