gpt4 book ai didi

ios - 数组值不在我的 TableView Controller 上返回

转载 作者:行者123 更新时间:2023-11-28 08:05:43 25 4
gpt4 key购买 nike

在这里,我尝试将导航 Controller 与 UISegmentController 一起使用。我在这里为三个不同的选项卡使用了开关盒。点击它应该改变 private public 和 protected 但可以看到值(value)在数组中声明。

    @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
}
}

最佳答案

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 :
retunValue = 1;// use this
break
}
return retunValue
}

关于ios - 数组值不在我的 TableView Controller 上返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45191285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com