[ad_1]
I would like flip UIView which is inside tableview if older information shouldn’t be matched with new information.The UIView is flipping however problem I’ve 3 or extra rows than it flipping constantly. I’ve written the code for changing a brand new information with outdated information however did not getting the place I am doing fallacious.
for instance :
In beneath picture blue coloration UIView is named as again and in crimson coloration UIView is named as lay.These two values again and lay is refreshing at each second. In cell for row at I’ve in contrast new again with outdated again however is getting flipped constantly.
Struct
struct SMatchOddsData{
var mktId:String
var runnerName:String
var again: Double
var lay: Double
init(mktId: String, runnerName:String, again: Double, lay: Double) {
self.mktId = mktId
self.runnerName = runnerName
self.again = again
self.lay = lay
}
}
class smtchOddsData {
var mtchoddsdatas:[SMatchOddsData] = []
public static let sharedInstance = smtchOddsData()
non-public init() {
self.mtchoddsdatas = []
}
public func add(mktId: String, runnerName:String, again: Double, lay: Double) throws {
mtchoddsdatas.append(SoccerMatchOddsData(mktId: mktId, runnerName:runnerName, again: again, lay: lay))
}
public func ReplaceAtIndex(Index:Int, mktId: String, runnerName:String, again: Double, lay: Double) throws {
mtchoddsdatas[Index] = SoccerMatchOddsData(mktId: mktId, runnerName:runnerName, again: again, lay: lay)
}
}
Array and Timer
var timer = Timer()
var mainArray = smtchOddsData.sharedInstance
In viewDidLoad
timer = Timer.scheduledTimer(timeInterval: 1.0, goal: self, selector: #selector(LiveViewController.refreshData), userInfo: nil, repeats: true)
MarketList Perform
On this api getting market id
func MarketList()
{
let params = [String : AnyObject]()
APIClient<MarketList>().API_GET(Url: strUrl, Params: params, Authentication: false, Progress: false, Alert: true, Offline: false, SuperVC: self, completionSuccess: { (resultdata) in
for response in resultdata
{
self.OddsInplay(marketId: response.marketID)
}
})
{ (error) in
print(error)
}
}
OddInplay Perform
On this perform im getting all information which I wish to show in tableview.
func OddsInplay(marketId:String)
{
let params = [String : AnyObject]()
APIClient<OddInplay>().API_GET(Url: strUrl, Params: params, Authentication: false, Progress: false, Alert: true, Offline: false, SuperVC: self, completionSuccess: { (resultdata) in
self.mainArray.mtchoddsdatas.removeAll()
for i in resultdata.first?.runners ?? []
{
attempt? self.mainArray.add(mktId: marketId, runnerName: i.runnerName ?? "", again: i.exchangePrices?.availableToBack?.first?.value ?? 0.0, lay: i.exchangePrices?.availableToLay?.first?.value ?? 0.0)
}
self.isStarted1 = self.isStarted1 + 1
self.ReplaceOddsInplay(marketId:marketId)
self.marketTableView.reloadData()
})
{ (error) in
print(error)
}
}
ReplaceOddInplay Perform
On this perform im changing outdated information with new information
func ReplaceOddsInplay(marketId:String)
{
let params = [String : AnyObject]()
APIClient<OddInplay>().API_GET(Url: strUrl, Params: params, Authentication: false, Progress: false, Alert: true, Offline: false, SuperVC: self, completionSuccess: { (resultdata) in
for i in resultdata.first?.runners ?? []
{
var isMatched = false
var index = 0
for j in self.mainArray.mtchoddsdatas
{
if j.runnerName == i.runnerName
{
isMatched = true
break;
}
index = index + 1;
}
if isMatched == true {
attempt? self.mainArray.ReplaceAtIndex(Index: index, mktId: marketId, runnerName: i.runnerName ?? "", again: i.exchangePrices?.availableToBack?[0].value ?? 0.0, lay: i.exchangePrices?.availableToLay?[0].value ?? 0.0)
}
}
})
{ (error) in
print(error)
}
}
TableView
func tableView(_ tableView: UITableView, numberOfRowsInSection part: Int) -> Int {
return mainArray.mtchoddsdatas.depend
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "matchOddsCell", for: indexPath) as! SoccerMatchOddTableViewCell
let obj = mainArray.mtchoddsdatas[indexPath.row]
cell.runnerName.textual content = obj.runnerName
let newback = String(obj.again)
if newback == "0.0"
{
cell.backLabel.textual content = "-"
}
else
{
if isStarted1 > 1 && (cell.backLabel.textual content ?? "" != newback)
{
UIView.transition(with: cell.backView, period: 1.0, choices: [.transitionFlipFromLeft], animations: nil, completion: nil)
}
cell.backLabel.textual content = newback
}
let newlay = String(obj.lay)
if newlay == "0.0"
{
cell.layLabel.textual content = "-"
}
else
{
if isStarted1 > 1 && (cell.layLabel.textual content ?? "" != newlay)
{
UIView.transition(with: cell.layView, period: 1.0, choices: [.transitionFlipFromLeft], animations: nil, completion: nil)
}
cell.layLabel.textual content = "(newlay)"
}
return cell
}
I wish to flip UIView if outdated again shouldn’t be equal to newback and if oldlay shouldn’t be equal to newlay.Can somebody helpme with this.
My Output
[ad_2]