I did IOS development but new to OSX. I am facing problem that I delete the row in NStableView successfully by clicking the button in row of table but when I click on add button the deleted row appears again and then its not deleted. Here is my delete function
func delIssue(_ sender:NSButton)
{
let btn = sender
if btn.tag >= 0
{
let issueValue = issueKeys[btn.tag]
for index in 0..<issueName.count
{
if issueValue == issueName[index]
{
issueName.remove(at: index)
rowCount = rowCount - 1
self.tableView.removeRows(at: NSIndexSet.init(index: index) as IndexSet , withAnimation: .effectFade)
self.tableView.reloadData()
break
}
}
}
}
rowCount is basically variable which I increment when row is added and decrement when row is deleted respectively. My adding Row function is
@IBAction func addRow(_ sender: Any)
{
rowCount += 1
DispatchQueue.main.async
{
self.tableView.reloadData()
}
}
And data source is
func numberOfRows(in tableView: NSTableView) -> Int
{
return rowCount
}