I have three arrays, for three cells of the control segment. I made one ViewController. And the array began to be scattered around cells, but I encountered a problem where it does not work for me to make the cell unit become the first. Now I want to remake.
import UIKit
import Parse
class PrognozSegmentViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {
var soccerString = [Soccer]()
var basketString = [Basketball]()
var tennisString = [Tennis]()
var refresh : UIRefreshControl!
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var segmentControl: UISegmentedControl!
@IBAction func btnSegment(_ sender: Any) {
tableView.reloadData()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var returnSport = 0
switch (segmentControl.selectedSegmentIndex) {
case 0 :
returnSport = soccerString.count
break
case 1 :
returnSport = basketString.count
break
case 2 :
returnSport = tennisString.count
break
default :
break
}
return returnSport
}
You can take out var returnSport from 'numberOfRowsInSection' method
var returnSport = 0
var soccerString = [Soccer]()
var basketString = [Basketball]()
var tennisString = [Tennis]()
var refresh : UIRefreshControl!
and change value type from Any to UISegmentedControl
@IBAction func btnSegment(_ sender: Any) {
returnSport = sender.selectedSegmentIndex
tableView.reloadData()
}
When you reload Data, you invoke numberOfRowsInSection method again and change returnSport variable
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.