简体   繁体   English

尝试从数组中快速删除时,不应删除 tableview 单元格中的最后一个单元格

[英]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.

相关问题 当我从 tableview 单元格中删除单元格时,未删除的单元格会重复 SWIFT - When I delete cell from tableview cells that are not deleted are duplicated SWIFT 当我在tableview中添加单元格数组时查看最后一个单元格 - View last cell when i add array of cell in tableview 当tableview单元符合Swift标准时,尝试更新集合视图 - Trying to update a collection view when tableview cell matches a criteria Swift 在Swift中,如何保存自定义视图中的数据,以便在单元出队时不会被删除? - In Swift, how should I save data from a custom view so that it is not deleted when a cell is dequeued? 当点击 UIButton (Swift) 时如何从另一个 ViewController 的 TableView 中删除一个单元格 - How to remove a cell from a TableView from another ViewController when tap on UIButton (Swift) 迅速地为tableView部分和tableView单元格填充一个数组 - Populate an array for the tableView section and the tableView cell, swift Swift - 在 Button-Tap 后从 TableView 中删除单元格 - Swift - remove cell from TableView after Button-Tap 当我从TableView上的按钮操作中删除单元格时,应用程序崩溃了-iOS Swift - When i remove cell from TableView on button action the app is crashed - iOS Swift 如何快速显示来自数组数组的tableview单元格中的数据 - How to display the data in the tableview cell from the array of array in swift 如何使用 Swift 中的按钮从数组更新 tableView 中的单元格? - How to update cell in a tableView from array by using button in Swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM