1
ここでは、UISegmentControllerでナビゲーションコントローラを使用しようとしています。ここでは3つの異なるタブのスイッチケースを使用しています。それをタップすると、 はプライベートパブリックを変更し、保護されますが、 が配列で宣言されている値を見ることができます。配列の値がテーブルビューのコントローラに返されない
@IBOutlet var myTableView: UITableView!
@IBOutlet var mySegmentControll: UISegmentedControl!
var privateList:[String] = ["Private Item 1","Private Item 2"]
var protected:[String] = ["Protected 1","protected 2"]
var publicList:[String] = [" public 1","Public 2"]
override func viewDidLoad() {
super.viewDidLoad()
myTableView.delegate = self;
myTableView.dataSource = self;
}
私のコードはcell1を返すことはできません。エラーはありませんが、私の配列は出力されていません。
@IBAction func refreshbtn(sender: AnyObject)
{
}
@IBAction func mySegmentValueChanged(sender: AnyObject) {
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var retunValue = 0
switch (mySegmentControll.selectedSegmentIndex){
case 1 :
retunValue = privateList.count
break
case 2:
retunValue = publicList.count
break
case 3:
retunValue = protected.count
break
default :
break
}
return retunValue
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell1 = tableView.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath)
switch (mySegmentControll.selectedSegmentIndex){
case 1:
cell1.textLabel!.text = privateList[indexPath.row]
break
case 2:
cell1.textLabel!.text = publicList[indexPath.row]
break
case 3:
cell1.textLabel!.text = protected[indexPath.row]
break
default :
cell1.textLabel?.text = "Boat"
break
}
//cell.petname.text
return cell1
}
}
'retunValue'がnumberOfRowsInSection''で返さ何mySegmentValueChanged – Miknash
でself.tableView.reloadDataを()に追加しますか?あなたのsegmentedControlledは0ではなく1から開始しますか?また、 'mySegmentValueChanged'はデータをリロードするようなことはしません。 – Larme
スイッチのケースにブレークは必要ありません。スイフトスイッチのケースはカスケードしません。 –