UITableView滚动和原型显示

时间:2014-10-06 00:12:31

标签: uitableview scroll

我是iOS新手并尝试使用Swift。我正在构建一个页面,列出表格原型中的图像和标签。将有多个图像因此图像将必须水平滚动并且垂直地滚动表格。我通过相当多的样本阅读并尝试建设,但它无法正常工作。不确定默认情况下表格视图是否滚动。

以下是代码

导入UIKit

class tableViewController:UITableViewController {

@IBOutlet var tableVw: UITableView!

let cellIdentifier = "reuseIdentifier"
var dishDesc : Array<String> = ["Mushroom","Onion","Apple","Brinjal","Cucumber","Berry","Pizza","Pasta","Biriyani","Naan & Curry"]
var dishPrice : Array<String> = ["10","20","30","40","50","60","70","80","90","100"]
var dishImages : Array<String> = ["1.jpg","2.jpg","3.jpg","1.jpg","2.jpg","3.jpg","1.jpg","2.jpg","3.jpg","1.jpg"]
// var pageImages2 : Array<String> = ["1.jpg","2.jpg","3.jpg","1.jpg","2.jpg","3.jpg","1.jpg","2.jpg","3.jpg","1.jpg","2.jpg","3.jpg","1.jpg","2.jpg","3.jpg"]

override func viewDidLoad() {
    super.viewDidLoad()
    //self.tableVw.registerClass(UITableViewCell.self, forCellReuseIdentifier: self.cellIdentifier)

    // Uncomment the following line to preserve selection between presentations
    // self.clearsSelectionOnViewWillAppear = false

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    // #warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete method implementation.
    // Return the number of rows in the section.
    return dishDesc.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath) as UITableViewCell
    //var dishImageView : UIImageView = cell.contentView.viewWithTag(120) as UIImageView
    //dishImageView.image = UIImage (named: self.dishImages[indexPath.row])

    // Configure the cell...

    return cell
}

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let alert = UIAlertController(title: "Item selected", message: "You selected item \(indexPath.row)", preferredStyle: UIAlertControllerStyle.Alert)
    alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Cancel, handler: nil))
    self.presentViewController(alert, animated: true, completion: nil)
}

0 个答案:

没有答案