[英]The last cell in a tableview cell should not be deleted when trying to remove from array in swift
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.
现在最多 5 个数据我可以附加并显示在一个正在工作的单元格中,但在一个单元格中有一个删除按钮可以删除附加的数据。 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.在从数组中删除项目的函数中,您需要检查它的计数是否大于 1,如果不是,则显示吐司。 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()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.