【发布时间】: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