UITableView Using Swift

前端 未结 10 1442
温柔的废话
温柔的废话 2020-12-08 07:27

My TapCell1.swift

This is Custom UITableViewCell View

import UIKit

class TapCell1: UITableViewCell
{
    @IBOutlet var         


        
相关标签:
10条回答
  • 2020-12-08 08:23

    The solution is most likely pinpointed to setting the cell height manually as such:

    override func tableView(tableView:UITableView!, heightForRowAtIndexPath indexPath:NSIndexPath)->CGFloat
    {
        return 44
    }
    

    I believe it's an Xcode beta 6 bug.

    0 讨论(0)
  • 2020-12-08 08:23

    Try this following code:

    var cell = tableView.dequeueReusableCell(withIdentifier: "CustomCellTableView") as? CustomCellTableView
    
    0 讨论(0)
  • 2020-12-08 08:25

    It is Purely swift notation an working for me

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
    { 
    var cellIdentifier:String = "CustomFields" 
    var cell:CustomCell? = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? CustomCell
     if (cell == nil) 
    { 
    var nib:Array = NSBundle.mainBundle().loadNibNamed("CustomCell", owner: self, options: nil) cell = nib[0] as? CustomCell
     } 
    return cell! 
    }
    
    0 讨论(0)
  • 2020-12-08 08:27

    I finally did it.

    For TapCell1.swift

    import UIKit
    
    class TapCell1: UITableViewCell {
    
        @IBOutlet var labelTitle: UILabel
    
        init(style: UITableViewCellStyle, reuseIdentifier: String!) {
            super.init(style: UITableViewCellStyle.Value1, reuseIdentifier: reuseIdentifier)
        }
    }
    

    For NextViewController.swift

    import UIKit
    
    class NextViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
        @IBOutlet var tableView: UITableView
    
        var ListArray=NSMutableArray()
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            let nibName = UINib(nibName: "TapCell1", bundle:nil)
            self.tableView.registerNib(nibName, forCellReuseIdentifier: "Cell")
    
            for i in 0...70 {
                ListArray .addObject("Content: \(i)")
            }
        }
    
    
        func tableView(tableView: UITableView!, numberOfRowsInSection section: Int)->Int {
           return ListArray.count
        }
    
        func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
            return 51
        }
    
        func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
            return 1
        }
    
        func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell {
            let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as TapCell1
    
            //cell.titleLabel.text = "\(ListArray.objectAtIndex(indexPath.item))"
    
            cell.labelTitle.text = "\(ListArray.objectAtIndex(indexPath.row))"
    
            return cell
        }
    }
    

    My working code link: CUSTOMISED TABLE

    0 讨论(0)
提交回复
热议问题