我使用的帧是SMSegmentView,我无法在numberOfRowsInSection和cellForRowAtIndexPath中实现切换...当您在模拟器中启动时,通过按下索引段不会更改段表。我无法理解错误
import UIKit
class DailyStandingViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, SMSegmentViewDelegate {
@IBOutlet var standingTableView: UITableView!
let standingExersiseName = ["БЕГ", "ПРЫЖКИ", "ПРИСЕДАНИЯ", "ОТЖИМАНИЯ", "ТОЛЧЕК"]
let standingExersiseImage = ["bb", "bt", "ca", "co", "de"]
let sittingExersiseName = ["ПРИСЕД", "СКАЧКИ", "ПРИСЕДАНИЯ", "ОТЖИМАНИЯ", "ТОЛЧЕК"]
let sittingExersiseImage = ["bb", "bt", "ca", "co", "de"]
var segmentControler: SMSegmentView!
var alphaSegmentView: SMBasicSegmentView!
var seletionBar: UIView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
//СОЗДАЕМ СЕГМЕНТ
self.view.frame = CGRectMake(-5.0 , 0.0, self.view.frame.size.width + 10, 40.0)
self.view.backgroundColor = UIColor(red: 241.0/255.0, green: 83.0/255.0, blue: 84.0/255.0, alpha: 1.0)
let segmentFrame = CGRect(x: -5.0 , y: 0.0, width: self.view.frame.size.width + 10, height: 40.0)
self.segmentControler = SMSegmentView(frame: segmentFrame, separatorColour: UIColor(red: 241.0/255.0, green: 83.0/255.0, blue: 84.0/255.0, alpha: 1.0), separatorWidth: 0.0, segmentProperties: [keySegmentTitleFont: UIFont.systemFontOfSize(16.0), keySegmentOnSelectionColour: UIColor(red: 241.0/255.0, green: 83.0/255.0, blue: 84.0/255.0, alpha: 1.0), keySegmentOffSelectionColour: UIColor(red: 241.0/255.0, green: 83.0/255.0, blue: 84.0/255.0, alpha: 1.0)])
self.segmentControler.delegate = self
self.segmentControler.addSegmentWithTitle("STANDING", onSelectionImage: nil, offSelectionImage: nil)
self.segmentControler.addSegmentWithTitle("SITTING", onSelectionImage: nil, offSelectionImage: nil)
self.segmentControler.layer.borderColor = UIColor(red: 241.0/255.0, green: 83.0/255.0, blue: 84.0/255.0, alpha: 1.0).CGColor
self.seletionBar.frame = CGRect(x: 0.0, y: 33.5, width: self.segmentControler.frame.size.width/CGFloat(self.segmentControler.numberOfSegments), height: 6.0)
self.seletionBar.backgroundColor = UIColor.whiteColor()
self.segmentControler.selectSegmentAtIndex(0)
self.view.addSubview(self.segmentControler)
}
func segmentView(segmentView: SMBasicSegmentView, didSelectSegmentAtIndex index: Int) {
let placeSelectionBar = { () -> () in
var barFrame = self.seletionBar.frame
barFrame.origin.x = barFrame.size.width * CGFloat(index)
self.seletionBar.frame = barFrame
}
if self.seletionBar.superview == nil {
self.segmentControler.addSubview(self.seletionBar)
placeSelectionBar()
}
else {
UIView.animateWithDuration(0.3, animations: {
placeSelectionBar()
})
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var returnValue = 0
switch (segmentControler.indexOfSelectedSegment) {
case 0: // NOT WORK ON SIMULATOR
returnValue = standingExersiseName.count
break
case 1: // NOT WORK ON SIMULATOR
returnValue = sittingExersiseName.count
break
default:
break
}
return returnValue
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let myCell = tableView.dequeueReusableCellWithIdentifier("myCell", forIndexPath: indexPath)
switch (segmentControler.indexOfSelectedSegment) {
case 0: // NOT WORK ON SIMULATOR
myCell.textLabel?.text = standingExersiseName[indexPath.row]
myCell.imageView!.image = UIImage(named:standingExersiseImage[indexPath.row])
break
case 1: // NOT WORK ON SIMULATOR
myCell.textLabel?.text = sittingExersiseName[indexPath.row]
myCell.imageView!.image = UIImage(named:sittingExersiseImage[indexPath.row])
break
default:
break
}
return myCell
}
答案 0 :(得分:0)
我们必须添加到didSelectSegmentAtIndex" standingTableView.reloadData()"