Set plus and minus images in cell for different index iOS swift

 Problem:

I want to add button in end of the cell.I want to set image plus in first index of row other indexes will have minus image.

For first index button will  only add the indexes.Other indexes had an option for delete the index like minus.

How to achieve that?

Solution:

In cell add the below to achieve that.

            let myCell = tableView.dequeueReusableCell(withIdentifier: "myCell") as! myCell

            

            if indexPath.row == 0 {

                myCell.addbtn.setImage(UIImage(named:"addImg"), for: .normal)

            } else {

                myCell.addbtn.setImage(UIImage(named:"minusImg")?, for: .normal)


            }


            myCell.addbtn.rx.tap.asDriver()

                .drive(onNext: { [weak self] in

                    self?.view?.endEditing(true)

                    let isAdd = indexPath.row == 0

                if isAdd {

                    // add functionality here

                    } else {
                     // Remove functionality here

                        }

                }).disposed(by: myCell.disposebag)

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift