Entering data into textfield, when clicked on add button then that textfield text gets appended into an array and is displayed in table cell. Now max 5 data i can append and show it in a cell which is working but in a cell there is a delete button which deletes the data appended. Now i want that when deleting the entry from cell one by one, the last remaining data in a cell should not be deleted and a toast message should be displayed saying that mandatory data cannot be deleted. Right now i am removing the data at a given index but all data is being deleted right now beacuse i dont know which condition to put for last cell not being deleted. Please help me
My code :
var rowIndex = Int()
@objc func deletecontact(sender: uibutton)
{
rowIndex = sender.tag
Self.openDeleteDialogPopup()
}
IBAction weak var func yesBtnClicked(sender:uibutton)
{
MyArr.remove(at: rowIndex)
Mytableview.reloaddata()
}
In the function where you are deleting the item from the array you need to check on if it has a count greater than 1 or not, if it is not, then you show the toast. If it is then you delete the row
@IBAction weak var func yesBtnClicked(sender:UIButton) {
guard MyArr.count > 1 else { //If we have more than one item, then don't enter the else block
//showToastHere
return
}
MyArr.remove(at: rowIndex)
MyTableview.reloadData()
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.