I'm trying to present a label every time the user double taps on my cell. I can detect the taps and I can execute code from them but I'm having an issue with the labels. For some reason the labels are being added two sometimes three cells below the one it should be added on. I need the label to be added on the cell that was tapped, shouldn't be to hard to do.
Here is my code, thanks in advance.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
static NSString *CellIdentifier = @"cell";
Cell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (nil == cell)
{
cell = [[Cell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
PFObject *tempObject = [_myArray objectAtIndex:indexPath.row];
NSString *currentUser = [[PFUser currentUser]username];
//NSLog(@"%@",tempObject);
NSArray *test = [tempObject valueForKey:@"Like"];
//NSLog(@"%lu",(unsigned long)test.count);
NSTimeInterval now = [[[NSDate alloc] init] timeIntervalSince1970];
if ((now - lastClick < 0.3) & [indexPath isEqual:lastIndexPath]) {
//cell.test.hidden = NO;
CGRect frame = CGRectMake(0,0, 80, 40);
UILabel *label1 = [[UILabel alloc]init];
label1.frame = frame;
label1.text = @"first label";
[cell.contentView addSubview:label1];
if ([test containsObject:currentUser]) {
NSLog(@"1");
[tempObject removeObject:currentUser forKey:@"Like"];
[tempObject saveInBackground];
}else {
NSLog(@"2");
[tempObject addUniqueObject:currentUser forKey:@"Like"];
[tempObject saveInBackground];
}
}
lastClick = now;
lastIndexPath = indexPath;
}
Aucun commentaire:
Enregistrer un commentaire