iphone - didSelectRowAtIndexPath: カスタムセルを長押しした後にのみ呼び出されます 質問する

iphone - didSelectRowAtIndexPath: カスタムセルを長押しした後にのみ呼び出されます 質問する

私はテーブル ビュー ベースのアプリケーションを 1 つ作成しています。テーブル用にカスタム テーブル セルを作成しました。このセルには、2 つのラベル、1 つの画像、1 つのボタンが含まれています。テーブル ビューのデータ ソース メソッドは正常に動作しています。カスタム セルとビュー コントローラ クラスの両方に xib を使用しており、デリゲートとデータ ソースをファイルの所有者に接続しています。ただし、問題は、テーブル行を選択したときに didSelectRowAtIndexPath が起動しないことです。前述のように、起動する唯一の方法は、セルを 3 ~ 4 秒間押し続けることです。なぜこのようなことが起こるのか、誰かご存知ですか?

何かアドバイスがあればよろしくお願いします。

これが私のテーブルビューメソッドです。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [finalAddonsArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    NewCustomCell *cell = (NewCustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"NewCustomCell" owner:self options:nil];
        cell=[nib objectAtIndex:0];
    }

    Addons *addons1=[[Addons alloc]init];
    addons1= [finalAddonsArray objectAtIndex:indexPath.row];

    if (addons1.data == nil) {
        cell.ivCategory.image = [UIImage imageNamed:@"blogo.jpg"];
    }
    else
    {
        cell.ivCategory.image=[UIImage imageWithData:addons1.data];
    }

    cell.lblTitle.text = addons1.name;
    if (addons1.price == nil) {
        cell.lblPrice.text = nil;
    }
    else{
        cell.lblPrice.text = [NSString stringWithFormat:@"%@ rs",addons1.price];
    }
    [cell.button addTarget:self
                    action:@selector(editButtonPressed:)
          forControlEvents:UIControlEventTouchUpInside];

    cell.button.tag=indexPath.row;
    index = indexPath;
    cell.selectionStyle = UITableViewCellSelectionStyleGray;

    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"sjcjksbcjksbcfkebscf1234567890");
}

もう 1 つ、カスタム セルの代わりにデフォルトの UITableViewCell を使用している場合も問題は同じで、デリゲート メソッドが起動しません。

カスタム セル プロパティ:

ここに画像の説明を入力してください ここに画像の説明を入力してください

ベストアンサー1

タップ ジェスチャ認識機能を追加したため、同じ問題が発生しました。ジェスチャ認識機能を使用している場合は、それを削除して、それが問題の原因かどうかを確認してください。

編集:Aliがコメントした解決策:タップジェスチャを使用した場合は、[tap setCancelsTouchesInView:NO];

おすすめ記事