ios - swift insert new static cells tableview -
want add new cells. how can this? please help! try
override func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { if section == 1 { return 3 + eventdates.count } else { return super.tableview(tableview, numberofrowsinsection: section) } } override func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { if (indexpath.section == 0 && indexpath.row == 1) { eventdaysvisible = !eventdaysvisible tableview.reloaddata() tableview.insertrowsatindexpaths([nsindexpath(forrow: eventdates.count + 3, insection: 0)], withrowanimation: .automatic) tableview.reloaddata() } day in eventdates { print("obj: \(day)") } tableview.deselectrowatindexpath(indexpath, animated: true) }
i have 3 static cells , new cells needs insert after first if switch button.
var eventdates = friday, saturday, sunday
hope can me that.
import uikit
class viewcontroller: uiviewcontroller {
var cellcount = 1 @iboutlet weak var tableview: uitableview! override func viewdidload() { super.viewdidload() // additional setup after loading view, typically nib. } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. }
}
extension viewcontroller:uitableviewdatasource {
func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { return cellcount } func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { let cell = uitableviewcell() cell.backgroundcolor = uicolor.graycolor() return cell } func tableview(tableview: uitableview, shouldhighlightrowatindexpath indexpath: nsindexpath) -> bool { return true } func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { let eventdates = ["1", "2", "3"] var indexpathsarray = [nsindexpath]() rowcount in 0 ..< eventdates.count { indexpathsarray.append(nsindexpath(forrow: rowcount, insection: 0)) cellcount += 1 } tableview.beginupdates() tableview.insertrowsatindexpaths(indexpathsarray, withrowanimation: .automatic) tableview.endupdates() tableview.deselectrowatindexpath(indexpath, animated: true) }
}
Comments
Post a Comment