我的表视图控制器上没有返回数组值

时间:2017-07-19 12:55:32

标签: ios swift uitableview

这里我试图使用带有UISegmentController的导航控制器。我在这里使用了三个不同选项卡的开关盒。点击它 应该改变私人公众和受保护但可以看到哪些价值 在数组中声明。

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

1 个答案:

答案 0 :(得分:0)

  public static BigDecimal roundTo5Cents(BigDecimal amount)
  {
    amount = amount.multiply(new BigDecimal("2"));
    amount = amount.setScale(1, RoundingMode.HALF_UP);
    // preferred scale after rounding to 5 cents: 2 decimal places
    amount = amount.divide(new BigDecimal("2"), 2, RoundingMode.HALF_UP);
    return amount;
  }