Tablview с Holdgesture в ячейках невысвечивания - PullRequest
0 голосов
/ 02 апреля 2012

У меня есть табличное представление, и к ячейкам в нем добавлен UILongPressGestureRecognizer. Проблема в том, что как только ячейка коснулась, она подсвечивается, но как только мой длинный жест начинается (удерживая кнопку), подсветка исчезает. Жест работает, и он все еще удерживается, но немного сбивает с толку пользователя, потому что они не знают, удерживается ли он до сих пор. Как сделать так, чтобы камера оставалась выделенной на протяжении всего удержания.

некоторый код:

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        //add long press gesture for the audio AB (eventually VC and TP as well) list 
        //so that users can hold the cell and after 5 seconds have the dialpad for editing that entry
        UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
                                                    initWithTarget:self 
                                                    action:@selector(handleLongPress:)];
        longPress.minimumPressDuration = 1; 
        [cell addGestureRecognizer:longPress];

    }
    cell.textLabel.text = [self.tableArray objectAtIndex:indexPath.row];



    return cell;
}


- (void)handleLongPress:(UILongPressGestureRecognizer*)sender 
{ 
    //used to get indexPath of cell pressed
    UITableViewCell *cell = (UITableViewCell *)[sender view];

    //get the indexPath of cell pressed
    NSIndexPath *indexPath = [self.myTableView indexPathForCell:cell]; 

    //use the index press to figure out the proper join to hold
    self.sharedJoinNumber = indexPath.row+286 ;

}

1 Ответ

0 голосов
/ 02 апреля 2012

Я решил эту проблему с помощью

 //highlight the apprioriate cell
    [self.myTableView selectRowAtIndexPath:indexPath animated:FALSE scrollPosition:UITableViewScrollPositionNone];

сразу после - (void)handleLongPress:(UILongPressGestureRecognizer*)sender

однако теперь, если удержание отменено, следующую нажатую ячейку нужно дважды коснуться, чтобы выделить ее. В основном, следующее нажатие после отмены долгого нажатия не будет замечено. но я думаю, что это отдельный квест, который я подам соответственно. приведенный выше код решает мою проблему

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...