Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Custom Cells and TabBar

Hi,

I'm making an app based on tabBar with 4 views, every view have a tableView with custom Cells, the problem is just the cells on the first view Controller appear.

I dont know ow to make it appear on the rest of view Controllers (By the way, all customs cells are diferent).

Please Help me

Here some code:

1ª View Controller

import UIKit

import UIKit  

class HomeViewController: UIViewController, UITabBarControllerDelegate, UITableViewDataSource, UITableViewDelegate {  
    let CellIdentifier = "CellTarea";  
    @IBOutlet var tareasTable: UITableView!  
    let tareas = ["Revisar etiquetado leche Nido","Reponer yoghurt sin lactosa","Reponer Chocolates Sahne Nuss","Revisar etiquetado de Chamito","Reponer Nescafe Clasico 200 gr."]  
    override func viewDidLoad() {  
        super.viewDidLoad()  
        //Tabbar Config  
        self.tabBarController?.delegate = self;  
        for item in (self.tabBarController?.tabBar.items as NSArray!){  
            (item as! UITabBarItem).image = (item as! UITabBarItem).image?.imageWithRenderingMode(.AlwaysOriginal)  
            (item as! UITabBarItem).selectedImage = (item as! UITabBarItem).selectedImage?.imageWithRenderingMode(.AlwaysOriginal)  
            tareasTable.delegate=self  
            tareasTable.dataSource=self  

        }  
        // Do any additional setup after loading the view.  
    }  

    override func didReceiveMemoryWarning() {  
        super.didReceiveMemoryWarning()  
        // Dispose of any resources that can be recreated.  
    }  
    //MARK: - TableView  
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {  
        return 1  
    }  
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {  
        return 5  
    }  
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {  
        let cell:CustomTareasCell = tableView.dequeueReusableCellWithIdentifier(CellIdentifier, forIndexPath: indexPath) as! CustomTareasCell  
        cell.tareaLabel.text = tareas[indexPath.row];  
        cell.indiceLabel.text = String(indexPath.row+1);  
        return cell  
    }  


    /  
    // MARK: - Navigation  

    // In a storyboard-based application, you will often want to do a little preparation before navigation  
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {  
        // Get the new view controller using segue.destinationViewController.  
        // Pass the selected object to the new view controller.  
    }  
    */  

}  

2ª View Controller

import UIKit  

class ReportesViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {  
    let personas = ["Alexis Parra","Ernesto Jímenez","Paulina Torres","Juan Soto","Julio Gallardo"]  
    let fechas = ["24 de Septimbre","22 de Septimbre", "21 de Septimbre", "20 de Septimbre","18 de Septimbre"]  
    let textCellIdentifier = "CellReporte";  

    @IBOutlet var reportesTable: UITableView!  
    override func viewDidLoad() {  
        super.viewDidLoad()  
        // Do any additional setup after loading the view.  
        reportesTable.delegate = self;  
        reportesTable.dataSource = self;  
    }  

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

    //MARK: - TableView  
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {  
        return 1  
    }  
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {  
        return 5  
    }  
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {  
        let reportesCell:CustomReportesCell = tableView.dequeueReusableCellWithIdentifier(textCellIdentifier, forIndexPath: indexPath) as! CustomReportesCell  
        reportesCell.fecha.text = fechas[indexPath.row];  
        reportesCell.autor.text = personas[indexPath.row];  
        return reportesCell  
    }  
    /  
    // MARK: - Navigation  

    // In a storyboard-based application, you will often want to do a little preparation before navigation  
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {  
        // Get the new view controller using segue.destinationViewController.  
        // Pass the selected object to the new view controller.  
    }  
    */  

}  

Cells are like

import UIKit  

class CustomTareasCell: UITableViewCell {  
    @IBOutlet weak var tareaLabel: UILabel!  
    @IBOutlet weak var indiceLabel: UILabel!  

    override func awakeFromNib() {  
        super.awakeFromNib()  
        // Initialization code  
    }  

    override func setSelected(selected: Bool, animated: Bool) {  
        super.setSelected(selected, animated: animated)  

        // Configure the view for the selected state  
    }  

}  

Thank you in advance

Jorge Gutierrez