0110iosapp_table view 和slider

表格 项目 TableView0109

//
//  ViewController.swift
//  TableView0109
//
//  Created by Mac on 1/9/19.
//  Copyright © 2019 wjb. All rights reserved.
//

import UIKit

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
//    继承类里增加UITableViewDelegate,UITableViewDataSource,及必须有的两个方法,xcode会提供修复,自动加载两个必须方法
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 100
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = UITableViewCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: "cell")
        
        cell.textLabel?.text = String(indexPath.row + 1)
        
        return cell
    }
    

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }


}

表格和滑竿 项目 slider0109

//
//  ViewController.swift
//  slider0109
//
//  Created by Mac on 1/9/19.
//  Copyright © 2019 wjb. All rights reserved.
//

import UIKit

class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return 10
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = UITableViewCell(style: UITableViewCell.CellStyle.default, reuseIdentifier: "CELL")
        
        //cell.textLabel?.text = "test"
        
        cell.textLabel?.text = String(Int(sliderShow.value*20) * (indexPath.row+1))
        
        return cell
    }
    
    //滑竿要赋值一个变量和一个方法
    //视图slider变量赋值
    @IBOutlet weak var sliderShow: UISlider!
    //视图Table view变量赋值
    @IBOutlet weak var tableShow: UITableView!
    
    
    //视图slider 操作方法赋值 type类型选择 UISlider
    @IBAction func sliderChange(_ sender: UISlider) {
        //打印slider的value
        //print(sliderShow.value)
        //变换显示数字
        tableShow.reloadData()
    }
    
    
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }


}

猜你喜欢

转载自blog.csdn.net/whqwjb/article/details/86213605
今日推荐