0

我的 iOS 应用程序包含一个 tableView 并有一个今天的小部件扩展,其中还包含一个 tableView。两个 tableView 都可以包含具有两个按钮的单元格。tableViews 内容模式是“动态属性”,每个原型单元格都有自己的 UITableViewCell 类。在cellForRowAtIndexPath:我创建单元格中:

}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;
    
}

两个目标都是这样的:

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

最后:

-(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];

}

小部件和应用程序都使用完全相同的代码。现在我的问题是:
当我点击小部件上的按钮时,它会立即突出显示并发送请求。但是在我的应用程序中,只有按住按钮半秒钟,按钮才会突出显示。

我不知道为什么会发生这种情况,有人知道吗?

4

1 回答 1

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

将创建一个同步请求,而不是使用

[NSURLConnection sendAsynchronousRequest:request];
于 2015-06-19T11:48:54.417 回答