私の iOS アプリケーションには tableView が含まれており、tableView も含まれる今日のウィジェット拡張機能があります。どちらの tableView にも、2 つのボタンを備えたセルを含めることができます。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];
}
ウィジェットとアプリの両方がまったく同じコードを使用します。そして今、私の問題:
ウィジェットのボタンをタップすると、すぐに強調表示され、リクエストが送信されます。しかし、私のアプリでは、ボタンを 0.5 秒間押し続けた場合にのみ、ボタンが強調表示されます。
なぜこれが起こるのか、私にはわかりません。