Размах для редактирования UITableView работает только после нескольких жестких ударов - PullRequest
0 голосов
/ 19 сентября 2019

Я настраиваю UITableView с пролистыванием для редактирования функций, и я использую автоматическое расположение.В моем контроллере представления есть только UITableViewController с пользовательским UITabelViewCell.Проблема в том, что мне пришлось несколько раз провести пальцами по ячейкам, чтобы вызвать эти меню.Я получаю меню только после нескольких ударов.Иногда мне пришлось сильно ударить, чтобы сделать эту работу.Как я могу вывести эти меню плавно, как в Почтовом приложении iOS?

В методе viewDidLoad я включил

self.practiceGrouptableView.allowsMultipleSelectionDuringEditing = NO;

Я получилЭто решение из других подобных вопросов, но все же, оно не решает мою проблему.

Пожалуйста, просмотрите мой код.

- (UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellidentifier = [NSString stringWithFormat:@"MyPracticeGroupCell"];
    MyPracticeGroupCell *cell = (MyPracticeGroupCell *)[tableView dequeueReusableCellWithIdentifier:cellidentifier];

    CountryItem *item = [hospitalArray objectAtIndex:indexPath.row];
    cell.lblGroupname.text = [NSString stringWithFormat:@"%@", item.name];
    cell.lblDescription.text = [NSString stringWithFormat:@"%@", item.Description];
    return cell;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return hospitalArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewAutomaticDimension;
}
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"Entered here");
    UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Leave Group" handler:^(UITableViewRowAction *action, NSIndexPath *  indexPath) {
        NSLog(@"Leave Group");
    }];

    UITableViewRowAction *joinAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Join Group" handler:^(UITableViewRowAction * action, NSIndexPath * indexPath) {
        NSLog(@"Join Group");
    }];

    joinAction.backgroundColor = ApplicationDelegate.ButtonColor;


    NSArray *rowActionArray = [[NSArray alloc] initWithObjects:deleteAction, joinAction,  nil];

    return rowActionArray;
}

Когда я отлаживал, каждый раз, когда я проводил, метод "editActionsForRowAtIndexPath" былвызвал но меню не показывалось.Это было показано только после попытки несколько раз.Как только меню появилось, пролистывание следующей ячейки станет более плавным, и меню отобразится без каких-либо попыток.И снова, когда скрытое меню будет отображаться, потребуется несколько попыток, чтобы снова его отобразить.

1 Ответ

0 голосов
/ 19 сентября 2019

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

Еще одна вещь, покажите нам, пожалуйста, как вы инициализируете все свойства табличного представления и где (я полагаю, viewdidload)

static NSString *cellidentifier = @"CustomTableViewCell";
MyPracticeGroupCell *cell = (MyPracticeGroupCell *)[tableView dequeueReusableCellWithIdentifier:cellidentifier];
if (cell == nil) {
    // XXX You may have another way to create a brand new cell.
    // This is how I get it from my storyboard because the name of
    // my custom cell in storyboard is the same as cell id here (above.)
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:cellidentifier owner:self options:nil];
    cell = [nib objectAtIndex:0];
}
CountryItem *item = [hospitalArray objectAtIndex:indexPath.row];
cell.lblGroupname.text = [NSString stringWithFormat:@"%@", item.name];
cell.lblDescription.text = [NSString stringWithFormat:@"%@", item.Description];
return cell;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...