Issue while Expanding and Collapse of Table View Cell - swift

i have a button and some content in a cell. Now when i tap a button i want the cell to expand and collapse, which is working fine for cell whose button is tapped. Now issue is coming that when i have expanded one cell and try to expand another cell while keeping first cell expanded it close first the previous cell and than expand my second cell. I want to expand and collapse the cells parallel and can collapse any cell rather than to collapse first. I'm changing height of cell on click of button. This is my code for expanding and collapsing,
extension ActiveConsultantDetailVC : UITableViewDelegate, UITableViewDataSource
{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == 0
{
return 100
}
else if indexPath.row == 1
{
return 80
}
else if indexPath.row == 2
{
if (flag == true && indexPath.row == indexValue)
{
return UITableView.automaticDimension
}
else
{
return 40
}
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
else if indexPath.row == 2
{
let cell = consultantTableView.dequeueReusableCell(withIdentifier: "descriptionCell", for: indexPath) as! ConsultDescriptionTVC
indexDescription = indexPath
cell.expandBtn.addTarget(self, action: #selector(expandDescriptionView), for: .touchUpInside )
cell.selectionStyle = .none
return cell
}
}
#objc func expandDescriptionView()
{
let cell = consultantTableView.cellForRow(at: indexDescription) as! ConsultDescriptionTVC
indexValue = indexDescription.row
if flag && indexValue == indexDescription.row{
//statesDetailTableView.beginUpdates()
self.consultantTableView.reloadRows(at: [indexDescription], with: UITableView.RowAnimation.none)
// statesDetailTableView.endUpdates()
cell.expandBtn.setTitle("-", for: .normal)
flag = false
}
else{
//statesDetailTableView.beginUpdates()
self.consultantTableView.reloadRows(at: [indexDescription], with: UITableView.RowAnimation.none)
// statesDetailTableView.endUpdates()
cell.expandBtn.setTitle("+", for: .normal)
flag = true
}
}
As you can see when i tap it call a function that then expand height of cell. My UI Looks like this,

You just need to create 2 Cells in UITableView(In Storyboard). First cell for those who are not expandable and Second cell for the expandable.(In this case, now you don't need to change the Height of the CELL)
class TableVC: UITableViewController {
// MARK:- Constants And Vars
var isCellNAME1Expanded = false
var isCellNAME2Expanded = false
}
class TableVC: UITableViewDataSource, UITableViewDelegate {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "simpleCell", for: indexPath) as! SideMenuBasicTableViewCell
switch indexPath.row {
case 0:
cell.itemName.text = "HOME"
break
case 1:
cell.itemName.text = "About Us"
break
case 2:
if(isCellNAME1Expanded){
//expandedCell
let cell = tableView.dequeueReusableCell(withIdentifier: "expandedCell", for: indexPath) as! SideMenuBasicTableViewCell
cell.itemName.text = "Expanded- CEll1"
return cell
}else{
cell.arrowDownImageView.isHidden = false
cell.itemName.text ="Expanded- CEll1"
}
break
case 3:
if(isCellNAME2Expanded){
//expandedCell
let cell = tableView.dequeueReusableCell(withIdentifier: "expandedCell", for: indexPath) as! SideMenuBasicTableViewCell
cell.itemName.text = "Expanded- CEll2"
return cell
}else{
cell.arrowDownImageView.isHidden = false
cell.itemName.text = "Expanded- CEll2"
}
break
case 4:
cell.itemName.text = "Portfolio"
break
case 5:
cell.itemName.text = "Contacts8"
break
default:
break
}
return cell
}
//And in `DidSelectRow` Method
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if(indexPath.row == 2){
if(isCellNAME1Expanded){
isCellNAME1Expanded = false
tableView.reloadRows(at: [indexPath], with: .none)
}else{
isCellNAME1Expanded = true
tableView.reloadRows(at: [indexPath], with: .none)
}
}if(indexPath.row == 3){
if(isCellNAME2Expanded){
isCellNAME2Expanded = false
tableView.reloadRows(at: [indexPath], with: .none)
}else{
isCellNAME2Expanded = true
tableView.reloadRows(at: [indexPath], with: .none)
}
}else if(indexPath.row == 0){
// Handle it yourself
}else if(indexPath.row == 1){
// Handle it yourself
}else if(indexPath.row == 4){
// Handle it yourself
}else if(indexPath.row == 5){
// Handle it yourself
}
}
}

Related

Load More when reaching the end of a UITableView

I am trying to implement a load more function within a table view. I read the that code would go inside of the cellForRowAt func, but this is not working.
I have two UITableViews in this specific ViewController. Everything is working great until this.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if (tableView == userSearchesTableView) {
if let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? CellBasicItemInfo {
cell.isUserInteractionEnabled = true
let responseItems = userRecentSearches[indexPath.row]
cell.configureCell(item: responseItems)
cell.setNeedsLayout()
return cell
} else {
return CellBasicItemInfo()
}
} else {
if let cell = tableView.dequeueReusableCell(withIdentifier: "itemCell", for: indexPath) as? CellItems {
cell.isUserInteractionEnabled = true
let responseItems = resultsModelArray[indexPath.row]
cell.configureCell(item: responseItems)
cell.setNeedsLayout()
if (indexPath.row == self.resultsModelArray.count) {
print("REACHED THE BOTTOM") // does not print
}
return cell
} else {
return CellItems()
}
}
}
Is there another or better way to handle this functionality?
per comment (did not work)
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if (tableView == userSearchesTableView) {
if (indexPath.row == self.userRecentSearches.count) {
print("REACHED THE BOTTOM RECENT")
}
}
}
UPDATE
adding the follow worked for me.
...
if (indexPath.row == self.userRecentSearches.count - 2) {
print("REACHED THE BOTTOM RECENT")
}
...

UITableView not remembering selection when collapsing

I have a tableview with 3 collapsible sections. users can only select rows in section 3 and when they select it goes green. However, when this section is collapsed all the selections are forgotten and when I re-open the section, usually the first row is always green (though it shouldn't be). Sometimes, other sections end up being green too when they shouldn't - not sure what I've got wrong?
// Number of table sections
func numberOfSections(in tableView: UITableView) -> Int {
return 3
}
// Set the number of rows
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (self.expandedSectionHeaderNumber == section) {
// If markscheme, create the markscheme format
if (section == 2)
{
return self.markschemeRows.count
}
else
{
let arrayOfItems = self.sectionItems[section] as! NSArray
return arrayOfItems.count
}
} else {
return 0;
}
}
// Set titles for sections
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if (self.sectionNames.count != 0) {
return self.sectionNames[section] as? String
}
return ""
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 44.0;
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat{
return 0;
}
func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
//recast your view as a UITableViewHeaderFooterView
let header: UITableViewHeaderFooterView = view as! UITableViewHeaderFooterView
header.contentView.backgroundColor = UIColor.darkGray
header.textLabel?.textColor = UIColor.white
if let viewWithTag = self.view.viewWithTag(kHeaderSectionTag + section) {
viewWithTag.removeFromSuperview()
}
let headerFrame = self.view.frame.size
let theImageView = UIImageView(frame: CGRect(x: headerFrame.width - 32, y: 13, width: 18, height: 18));
theImageView.image = UIImage(named: "Chevron-Dn-Wht")
theImageView.tag = kHeaderSectionTag + section
header.addSubview(theImageView)
// make headers touchable
header.tag = section
let headerTapGesture = UITapGestureRecognizer()
headerTapGesture.addTarget(self, action: #selector(CaseViewController.sectionHeaderWasTouched(_:)))
header.addGestureRecognizer(headerTapGesture)
}
// Load the table data
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath) as! CustomTableCell
let section = self.sectionItems[indexPath.section] as! NSArray
cell.textLabel?.textColor = UIColor.black
cell.selectionStyle = .none
//cell.backgroundColor = .white
// Get the data from different arrays depending on the section
if indexPath.section == 2 {
cell.textData?.text = markschemeRows[indexPath.row]
} else {
cell.textData?.text = section[indexPath.row] as! String
}
return cell
}
func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
if indexPath.section == 0{
if indexPath.row == 0{
return nil
}
}
else if indexPath.section == 1{
if indexPath.row == 0{
return nil
}
}
return indexPath
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none)
let cell = tableView.cellForRow(at: indexPath)
cell?.backgroundColor = .green
}
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
let cell = tableView.cellForRow(at: indexPath)
if (cell?.backgroundColor == .green)
{
cell?.backgroundColor = .white
}
}
// MARK: - Expand / Collapse Methods
#objc func sectionHeaderWasTouched(_ sender: UITapGestureRecognizer) {
let headerView = sender.view as! UITableViewHeaderFooterView
let section = headerView.tag
let eImageView = headerView.viewWithTag(kHeaderSectionTag + section) as? UIImageView
if (self.expandedSectionHeaderNumber == -1) {
self.expandedSectionHeaderNumber = section
tableViewExpandSection(section, imageView: eImageView!)
} else {
if (self.expandedSectionHeaderNumber == section) {
tableViewCollapeSection(section, imageView: eImageView!)
} else {
let cImageView = self.view.viewWithTag(kHeaderSectionTag + self.expandedSectionHeaderNumber) as? UIImageView
tableViewCollapeSection(self.expandedSectionHeaderNumber, imageView: cImageView!)
tableViewExpandSection(section, imageView: eImageView!)
}
}
}
func tableViewCollapeSection(_ section: Int, imageView: UIImageView) {
let sectionData = self.sectionItems[section] as! NSArray
self.expandedSectionHeaderNumber = -1;
if (sectionData.count == 0) {
return;
} else {
UIView.animate(withDuration: 0.4, animations: {
imageView.transform = CGAffineTransform(rotationAngle: (0.0 * CGFloat(Double.pi)) / 180.0)
})
var indexesPath = [IndexPath]()
// If markscheme, different number needed
if (section == 2)
{
for i in 0 ..< markschemeRows.count {
let index = IndexPath(row: i, section: section)
indexesPath.append(index)
}
}
else
{
for i in 0 ..< sectionData.count {
let index = IndexPath(row: i, section: section)
indexesPath.append(index)
}
}
self.tableView!.beginUpdates()
self.tableView!.deleteRows(at: indexesPath, with: UITableView.RowAnimation.fade)
self.tableView!.endUpdates()
}
}
func tableViewExpandSection(_ section: Int, imageView: UIImageView) {
let sectionData = self.sectionItems[section] as! NSArray
if (sectionData.count == 0) {
self.expandedSectionHeaderNumber = -1;
return;
} else {
UIView.animate(withDuration: 0.4, animations: {
imageView.transform = CGAffineTransform(rotationAngle: (180.0 * CGFloat(Double.pi)) / 180.0)
})
var indexesPath = [IndexPath]()
// If markscheme, create the markscheme format
if (section == 2)
{
for i in 0 ..< markschemeRows.count {
let index = IndexPath(row: i, section: section)
indexesPath.append(index)
}
}
else
{
for i in 0 ..< sectionData.count {
let index = IndexPath(row: i, section: section)
indexesPath.append(index)
}
}
self.expandedSectionHeaderNumber = section
self.tableView!.beginUpdates()
self.tableView!.insertRows(at: indexesPath, with: UITableView.RowAnimation.fade)
self.tableView!.endUpdates()
}
}
The key thing to understand here is that the Cells are Reused when you say
let cell = tableView.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath) as! CustomTableCell
dequeueReusableCell basically reuses a previously loaded UITableViewCell and in your case you changed the background color of the cell to green
To get a better understanding of the concept consider reading some articles like this one on Reusing Cells
Changes in Code
What you should do considering the above in mind
var backgroundColors = [UIColor](repeating: UIColor.white, count: 10)
you have to save the state of the colors in a model (ideally you should make a custom struct)
now in cellForRowAt add this
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath) as! CustomTableCell
.
.
cell.backgroundColor = backgroundColors[indexPath.row]
// **EDIT**
let cellShouldBeSelected = backgroundColors[indexPath.row] == .green
if cellShouldBeSelected {
tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none)
}
.
.
return cell
}
And your didSelectRowAt and didDeselectRowAt should update the model
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.backgroundColors[indexPath.row] = .green
tableView.reloadRows(at: [indexPath], with: .none)
}
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
if (self.backgroundColors[indexPath.row] == .green) {
self.backgroundColors[indexPath.row] = .white
tableView.reloadRows(at: [indexPath], with: .none)
}
}
On second thought
Solution 2 (Recommended)
From you comments, i see you only need one selected cell at one time, assuming that keeping an array of backgroundColors is just a bad idea.
declare a int for the selected index
// -1 representing nothing is selected in the beginning
var selectedRow = -1
now your cellForRowAt will look like
let cell = tableView.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath) as! CustomTableCell
.
.
if indexPath.section == 2, indexPath.row == self.selectedRow {
cell.backgroundColor = .green
} else {
cell.backgroundColor = .white
}
.
.
return cell
}
And your didSelectRowAt
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 2 {
self.selectedRow = indexPath.row
tableView.reloadSections([2], with: .automatic)
}
}
And now you can remove didDeselectRowAt completely

Refactoring TableView with multiple cell types

Any suggestions regarding factoring a massive view controller, with multiple cell types, cell sizes. Because each cell has its own delegates, the view controller becomes super confusing when navigating through the file.
Or is this the standard approach to for multiple cell types? How would you go about building multiple with multiple sections & cells. Much thanks!
//Rows
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 && sectionArray[0].isExpanded {
return sectionArray.count
} else if section == 0 && sectionArray[0].isExpanded == false {
return sectionArray[0].section.count - 1
}
if section == 1 {
return 3
}
return 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 && indexPath.row == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "CreateFavoriteIconCell", for: indexPath) as! CreateFavoriteIconCell
cell.delegate = self
return cell
}
if indexPath.section == 1 {
switch indexPath.row {
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: "CreateFavoritePhotoCell", for: indexPath) as! CreateFavoritePhotoCell
cell.delegate = self
return cell
case 1:
let cell = tableView.dequeueReusableCell(withIdentifier: "CreateFavoriteLocationCell", for: indexPath) as! CreateFavoriteLocationCell
return cell
case 2:
let cell = tableView.dequeueReusableCell(withIdentifier: "CreateFavoriteDescriptionCell", for: indexPath) as! CreateFavoriteDescriptionCell
return cell
default:
return tableView.cellForRow(at: indexPath)!
}
}
return tableView.cellForRow(at: indexPath)!
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.section == 0 {
switch indexPath.row {
case 0:
tableView.rowHeight = 58
default:
tableView.rowHeight = 0
}
}
if indexPath.section == 1 {
switch indexPath.row {
case 0:
tableView.rowHeight = 120
case 1:
tableView.rowHeight = 60
case 2:
tableView.rowHeight = 160
default:
tableView.rowHeight = 0
}
}
return tableView.rowHeight
}

Show / Hide Sections in table view based on selection

i developing ipad application, this application for assets requests,
i have 6 checkboxes and table view like the image
i created 6 sections in table, i need when user select for ex laptop in table view only laptop section will appear and other sections will removed or hide.
this is my code
#objc func circleBoxValueChanged(sender: Checkbox) {
tblView.isHidden = false
switch sender.tag {
case 1:
print("1")
case 2:
print("2")
case 3:
print("3")
case 4:
print("4")
case 5:
print("5")
case 6:
print("6")
default:
break
}
print("circle box value change: \(sender.isChecked)")
}
// MARK: - TableView Delegate
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 200
}
func numberOfSections(in tableView: UITableView) -> Int {
return 6
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == 0 {
return "Laptop"
}else if section == 1 {
return "Mobile"
}else if section == 2 {
return "Ex Badge"
}
else if section == 3 {
return "VIP Badge"
}
else if section == 4 {
return "Gift"
}
else if section == 5{
return "Locker"
}else{
return "Other"
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return 1
}else if section == 1{
return 1
}else if section == 2{
return 1
}else if section == 3{
return 1
}else if section == 4{
return 1
}else if section == 5{
return 1
}else{
return 0
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
switch indexPath.section {
case 0:
let cell1 = tableView.dequeueReusableCell(withIdentifier: "cell1", for: indexPath) as! laptop_MobileTableViewCell
return cell1
case 1:
let cell1 = tableView.dequeueReusableCell(withIdentifier: "cell1", for: indexPath) as! laptop_MobileTableViewCell
return cell1
case 2:
let cell1 = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath) as! OtherRequstTableViewCell
return cell1
case 3:
let cell1 = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath) as! OtherRequstTableViewCell
return cell1
case 4:
let cell1 = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath) as! OtherRequstTableViewCell
return cell1
case 5:
let cell1 = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath) as! OtherRequstTableViewCell
return cell1
default:
let cell1 = tableView.dequeueReusableCell(withIdentifier: "cell2", for: indexPath) as! OtherRequstTableViewCell
return cell1
}
}
can you help me
You can try
struct Item {
var name:String
var isShown:Bool
}
let arr = [Item(name:"LapTop",isShown:true)] // and so--on
in numberOfSections
return arr.filter {$0.isShown}.count
in titleForHeader
return arr.filter{$0.isShown}[indexPath.section].name

SWIFT 3 and Firebase using tableEdit mode to insert data to firebase which updates my table array for tableview

SWIFT 3 and Firebase - I'm trying to use the UITable inEditing mode to insert cells into firebase and have a firebase listener that updates my arraty. My insertions to fire base are fine, but I keep getting an index out of range when I try to do the insertion with the new add button i created. Has anyone used Firebase with UITable inEditing mode to insert into a table and update firebase.
This is what I looking for:
enter image description here
The problem maybe be how I wrote the cellForAt:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
print("zzz indexPath index path row: \(indexPath.row)")
print("zzz indexPath name \(myPins[indexPath.row].pinName)")
print("ZZZ myPins Count \(myPins.count)")
let cell = tableView.dequeueReusableCell(withIdentifier: "PinCell", for: indexPath)
if indexPath.row == 0 && isEditing {
//this means we are in editing mode an we to add the cell that will be addPlace
//let indexPathOfFirstRow = IndexPath(item: 0, section: 0)
cell.textLabel?.text = "Add Place"
print("add place was called index.row is : \(indexPath.row)")
} else {
//let cell = tableView.dequeueReusableCell(withIdentifier: "PinCell", for: indexPath)
let pin = myPins[indexPath.row]
cell.textLabel?.text = pin.pinName
}
return cell
}
i get this error message: fatal error: Index out of range
Here is the rest of the table set up code:
//When the use press the editing button it will make the table enditable
override func setEditing(_ editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
//if the viw is in editing mode then we will set the table to be in enditing mode.
if isEditing {
//This is adding the addtional cell in for add place
tableView.beginUpdates()
let indexPath = IndexPath(row: 0, section: 0)
tableView.insertRows(at: [indexPath], with: .automatic)
// self.tableView.insertRows(at: [indexPathOfFirstRow], with: UITableViewRowAnimation.automatic)
tableView.endUpdates()
tableView.setEditing(true, animated: true)
} else {
//when the 'Done' is pressed this will take away the add button
tableView.beginUpdates()
let indexPathOfFirstRow = IndexPath(item: 0, section: 0)
self.tableView.deleteRows(at: [indexPathOfFirstRow], with: UITableViewRowAnimation.automatic)
tableView.endUpdates()
//otherwise the table will not be in editing mode.
tableView.setEditing(false, animated: false)
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//STEP 1 for adding a row that will fuction as add place
//If we are in editing mode a 1 will be return and the extra cell will be added
let adjustment = isEditing ? 1 : 0
//add the extra cell if we are in editing mode
return myPins.count + adjustment
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "PinCell", for: indexPath)
if indexPath.row == 0 && isEditing {
//this means we are in editing mode an we to add the cell that will be addPlace
//let indexPathOfFirstRow = IndexPath(item: 0, section: 0)
cell.textLabel?.text = "Add Place"
print("add place was called index.row is : \(indexPath.row)")
//addCell.addButton.tag = indexPath.row
//addCell.addButton.addTarget(self, action: "addPlace", for: .touchUpInside)
} else {
// let cell = tableView.dequeueReusableCell(withIdentifier: "PinCell", for: indexPath)
//this is the info I want to dispaly in the cell
let pin = myPins[indexPath.row]
cell.textLabel?.text = pin.pinName
return cell
}
//add the green plus button icon for the extra row added
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
// let indexRow = IndexPath(item: 0, section: 0)
if indexPath.row == 0 {
return .insert
}
return .delete
}
//delete with a with a swipe
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
print("pins count before deleate\(myPins.count)")
if editingStyle == .delete {
let pin = myPins[indexPath.row]
guard let currentUser = FIRAuth.auth()?.currentUser?.uid else {return}
rootRef.child(child.users.rawValue).child(currentUser).child(users.myPins.rawValue).child(plotToEdit!.plotID).child(pin.placeID).removeValue()
}
//When you press on the green plus button as appose to the row.
else if editingStyle == .insert {
let autocompleteController = GMSAutocompleteViewController()
autocompleteController.delegate = self
present(autocompleteController, animated: true, completion: nil)
}
}
//When in ending more I can slect the first row that is add places
func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
// let indexPathOfFirstRow = IndexPath(item: 0, section: 0)
if isEditing && (indexPath.row > 0) {
return nil
}
return indexPath
}