Wednesday, October 28, 2026
HomeiOS Developmentios - the way to populate tableview based mostly on button press-...

ios – the way to populate tableview based mostly on button press- swift

[ad_1]

Make two separate arrays of your knowledge one for Scheduled Shoots and the Different for Accomplished Shoots
Keep a Boolean Var to modify between them

var scheduledShoots: [YourModel] = [...]
var completedShoots: [YourModel] = [...]
var isScheduledShootSelected = true

Then in your desk view strategies do that

func tableView(_ tableView: UITableView, numberOfRowsInSection part: Int) -> Int {
        return isScheduledShootSelected ? scheduledShoots.rely : completedShoots.rely
 }

additionally in your cellForRowAt test on isScheduledShootSelected and populate respective knowledge

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
     if isScheduledShootSelected {
        //Populate scheduledShoots array knowledge 
     } else {
        //Populate completedShoots array knowledge 
     }

     return yourCell
   }

Now in your Motion Strategies

@IBAction func scheduledShootPressed() {
   isScheduledShootSelected = true
   tableView.reloadData()
}

@IBAction func completedShootPressed() {
   isScheduledShootSelected = false
   tableView.reloadData()
}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments