0

私は 1 つのアプリを作成しています。ここでは、UITableView の URL からいくつかの RSS コンテンツを表示しています。しかし、ここで私が望むのは、ユーザーが UITableViewCell を 5 秒以上クリックして押したままにして、他の機能を実行することです。単一の選択を知り、UITableViewCellの選択を押し続ける方法が欲しいだけです。

ありがとう

4

1 に答える 1

6

UILongPressGestureReconizerをセルに追加し、minimumPressDuration5 に設定する必要があります。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
        UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
        longPress.minimumPressDuration = 5.0;
        [cell addGestureRecognizer:longPress];

    }

    // Do additional setup

    return cell;
}

編集:

を使用している場合prototypeCells!cell条件が真になることはないので、次のように記述する必要があることに注意してください。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }
    if (cell.gestureRecognizers.count == 0) {
        UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
        longPress.minimumPressDuration = 5.0;
        [cell addGestureRecognizer:longPress];
    }
    return cell;
}
于 2013-01-02T13:07:57.777 に答える