Как создать расширяющийся и свертываемый ряд в UITableView - PullRequest
0 голосов
/ 14 мая 2018

Как создать расширяющийся и свернутый ряд в UITableView,

Я следил за этим видео: "https://www.youtube.com/watch?v=OYaI5ASpsOE" после нажатия на ячейку я получил следующую ошибку.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to compare <NSIndexPath: 0x600000029560> {length = 2, path = 0 - 18446744073709551615} with object of different class: NSArray'

Ответы [ 2 ]

0 голосов
/ 14 мая 2018

Ниже кода делегата таблицы и источника данных, который я использовал, сбой не воспроизводится для меня

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

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

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ExpandingCell *cell = (ExpandingCell *)[tableView dequeueReusableCellWithIdentifier:CELL_IDENTIFIER forIndexPath:indexPath];
    if (cell == nil) {
        NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"Expanding Cell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    cell.lblrow.text = self.arrow[indexPath.row];
    cell.lblrowtitle.text = self.arrowtitle[indexPath.row];
    cell.lblfruit.text = self.arrFruit[indexPath.row];
    NSInteger cal = (indexPath.row) * 25;
    cell.lblcalcal.text = [NSString stringWithFormat:@"%ld",(long) cal];

    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return (self.selectedIndex == indexPath.row) ? 120  : 45 ;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.selectedIndex == indexPath.row) {
        self.selectedIndex = -1;
        [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
        return;
    }
    if (self.selectedIndex == -1) {
        NSIndexPath *prev = [NSIndexPath indexPathForRow:self.selectedIndex inSection:0];
        self.selectedIndex = indexPath.row;
        [tableView reloadRowsAtIndexPaths:@[prev] withRowAnimation:UITableViewRowAnimationFade];
    }
    self.selectedIndex = indexPath.row;

    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];

}
0 голосов
/ 14 мая 2018

Пожалуйста, используйте Эта библиотека. Просто добавьте его в свой проект, используя POD.

pod 'ExpandableCell'

Импортируйте его в свой viewController

import ExpandableCell

Сделать ExpandableTableView в раскадровке или в коде

@IBOutlet var tableView: ExpandableTableView!

Inherit ExpandableDelegate

class ViewController: UIViewController, ExpandableDelegate 

Установить делегата

tableView.expandableDelegate = self

Ссылка: https://github.com/younatics/ExpandableCell

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