【问题标题】:iOS UIButton Touch-Up-Inside weird behavioriOS UIButton Touch-Up-Inside 奇怪的行为
【发布时间】:2015-06-19 11:20:25
【问题描述】:

我的 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];

}

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

我不知道为什么会这样,有人知道吗?

【问题讨论】:

  • 不要像这样设置按钮标签 " Button_cell.ON_Button.tag = indexPath.row; Button_cell.OFF_Button.tag = indexPath.row;" .直接从 viewWithTag 属性设置。
  • 但是我需要将按钮标签设置为 indexPath.row,如何使用 viewWithTag 来做到这一点?单元格的顺序可能会改变

标签: ios objective-c uitableview uibutton touch-up-inside


【解决方案1】:
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];

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

[NSURLConnection sendAsynchronousRequest:request];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-23
    • 2012-12-01
    • 2014-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多