Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Load custom cell(Xib) in UITableView in swift

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 10.5k
    Comment on it

    hello friends,
    if you would like to Load custom cell(Xib) in UITableView in swift ,you may use the following code ->

     func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            return array.count;   //This function returns number of rows in table view
        }
    
    
     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
            var cell:YourTableViewCell! = tableView.dequeueReusableCellWithIdentifier("YourTableViewCell", forIndexPath:indexPath)as! YourTableViewCell
            // This function actually loads the xib
            if cell == nil{
                let cellnib = [NSBundle.mainBundle().loadNibNamed("YourTableViewCell", owner:self, options: nil)]
                cell = cellnib.first! as! YourTableViewCell
    
            }
         // Do additional code here
        }
    

    Dont forget to register nib in viewDidLoad

    override func viewDidLoad() {
    
            super.viewDidLoad()
           // registering your nib
            let yourNibName = UINib(nibName: "YourTableViewCell", bundle: nil)
            tableView.registerNib(yourNibName, forCellReuseIdentifier: "YourTableViewCell")
    
            // Do any additional setup after loading the view.
        }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: