iOS UIButton Touch-Up-Inside weird behavior

237 views Asked by At

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?

1

There are 1 answers

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

will create a synchronous request instead use

[NSURLConnection sendAsynchronousRequest:request];