基本的に、ビュー内のセルを操作するには、タップとタップ アンド ホールド ジェスチャの 2 つが必要です。タップ アンド ホールド ジェスチャは次のように機能します。
-(void) longTap:(UILongPressGestureRecognizer *)gestureRecognizer
{
NSLog(@"gestureRecognizer= %@",gestureRecognizer);
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan)
{
NSLog(@"longTap began");
CGPoint p = [gestureRecognizer locationInView:self.tableView];
NSIndexPath *indexPath = [myTable indexPathForRowAtPoint:p];
if (indexPath == nil)
{
NSLog(@"long press on table view but not on a row");
}
else
{
NSLog(@"long press on table view at row %d", indexPath.row);
switch (indexPath.row)
{
case 0:
del.tableRowNumber = 0;
break;
case 1:
del.tableRowNumber = 1;
break;
case 2:
del.tableRowNumber = 2;
break;
case 3:
del.tableRowNumber = 3;
break;
case 4:
del.tableRowNumber = 4;
break;
case 5:
del.tableRowNumber = 5;
break;
}
}
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"MealPlannerRecipeTypeViewController"];
[self.navigationController pushViewController:controller animated:YES];
}
}
選択された行に応じて、シングルトン クラスの値を特定の値に設定するには、このジェスチャが必要です。どの行が選択されていても、この値は常に 0 ?! 誰でも理由を教えてもらえますか?
質問の 2 番目の部分は、私の tableview デリゲートの 1 つが次のようになっていることです。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
RecipeInfo *recipeInfo = recipeInfoArray[indexPath.row];
cell.textLabel.text = recipeInfo.name;
// Add long tap for the main tiles
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTap:)];
[cell addGestureRecognizer:longPressGesture];
}
return cell;
}
テーブル ビューのすべての行に、最初の行と同じ情報が含まれていますか? どうしてこれなの?
ありがとう