Я использовал пользовательский UITableViewCell с xib.В UITableViewCell я использовал представление коллекции.все работает хорошо, но есть проблема, когда я расширяю и разрушаю ячейку.Что я хочу сделать, так это то, что когда я нажимаю на ячейку, она расширяется, если она больше не разрушается.Я изменил ограничение для этого, но он не работает, он работает, когда я дважды нажимаю кнопку.мой код:
#pragma mark:tbl view delegate data source
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
NSLog(@"%lu",(unsigned long)postArr.count);
return postArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
rewardCell*cell = [tableView dequeueReusableCellWithIdentifier:@"simpleCellReward"];
if (cell == nil) {
cell = [[rewardCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"simpleCellReward"];
}
[cell.showRewardBtn addTarget:self action:@selector(showRewards:) forControlEvents:UIControlEventTouchUpInside];
cell.showRewardBtn.tag = indexPath.row+1;
cell.collectionContainer.layer.cornerRadius = 3.0;
cell.collectionContainer.clipsToBounds = true;
cell.lblTitle.text = [NSString stringWithFormat:@"My Reward %ld",(long)indexPath.row];
if (selectIndexForReward == indexPath.row) {
if (cell.collectionHeightConstraint.constant == 0) {
cell.collectionHeightConstraint.constant = 97;
}else{
cell.collectionHeightConstraint.constant = 0;
}
}
[cell layoutIfNeeded];
[cell.collectionView layoutIfNeeded];
return cell;
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
if ((int)indexPath.row == (slot-2)) {
page = page+1;
slot = slot+10;
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:true];
[apiObj getPostData:@{@"page":[NSString stringWithFormat:@"%d",page],@"user_id":user.usrid}];
}
}
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewAutomaticDimension;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewAutomaticDimension;
}
примечание: существует более одной настраиваемой ячейки, которая управляется условием, но мне нужна расширяемая ячейка в конкретной настраиваемой ячейке, которая написана выше в коде.
над кодомсработало, когда я постучал дважды.В ячейке есть кнопка, на которую я устанавливаю цель и, используя эту цель, перезагружаю таблицу.код для этого
#pragma mark:ShowReward
-(void)showRewards:(UIButton*)sender{
selectIndexForReward= (int)sender.tag-1;
//[self.tblView reloadData];
rewardCell *cell =(rewardCell *)sender.superview.superview.superview; //change with your class
NSIndexPath *indexPath = [self.tblView indexPathForCell:cell];
[self.tblView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
}