0

My iOS application contains a tableView and has a today widget extension which also contains a tableView. Both tableViews can contain cells which feature two buttons. The tableViews content mode is "dynamic properties" and each prototype cell has its own UITableViewCell class. In the cellForRowAtIndexPath: I create the cells:

}else if (...){
    
    static NSString *CellIdentifier_Item_Button = @"Button_Cell";
    BTNCell *Button_cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier_Item_Button forIndexPath:indexPath];
    Button_cell.ON_Button.tag = indexPath.row;
    Button_cell.OFF_Button.tag = indexPath.row;
    [Button_cell.ON_Button addTarget:self action:@selector(ON_Button_clicked:) forControlEvents:UIControlEventTouchUpInside];
    [Button_cell.OFF_Button addTarget:self action:@selector(OFF_Button_clicked:) forControlEvents:UIControlEventTouchUpInside];

    return Button_cell;
    
}

and both targets like this:

-(void)OFF_Button_clicked:(UIButton*)sender
{
    //some additional code here
    [self sendRequest:url];
}

and finally:

-(void) sendRequest:(NSString *)IP{
NSURL *requestURL = [NSURL URLWithString:IP];
NSURLRequest *request = [NSURLRequest requestWithURL:requestURL
                                         cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
                                     timeoutInterval:10.0];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];

}

Both widget and app use the exact same code. And now my problem:
when I tap on a button on the widget, it gets highlighted immediately and the request gets send. But in my app, the button gets only highlighted if you hold the button for like half a second.

I have no idea why this happens, anyone ideas?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • Don't set button tag like this " Button_cell.ON_Button.tag = indexPath.row; Button_cell.OFF_Button.tag = indexPath.row;" . Set directly from viewWithTag Property. – Vineesh TP Jun 19 '15 at 13:19
  • But i need to set the buttons tag to indexPath.row, how do i do this with viewWithTag? The order of the Cells may change – MothaFvckaJones Jun 20 '15 at 10:24

1 Answers1

0
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];

will create a synchronous request instead use

[NSURLConnection sendAsynchronousRequest:request];
Vineesh TP
  • 7,755
  • 12
  • 66
  • 130
Ankit Sachan
  • 7,690
  • 16
  • 63
  • 98