繁体   English   中英

iOS UIButton Touch-Up-Inside 奇怪的行为

[英]iOS UIButton Touch-Up-Inside weird behavior

我的 iOS 应用程序包含一个 tableView,并且有一个 today 小部件扩展,其中还包含一个 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];

}

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

我不知道为什么会发生这种情况,任何人的想法?

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

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

[NSURLConnection sendAsynchronousRequest:request];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM