0
votes

I have this problem after setting up UItabbar in app delegate.

The problem are :

  1. The app crash only after press the discovery tab bar.
  2. Home + Add + Profile ViewControllers are Black.

Thank you in advance

var discoveryList = ["topic","topic","topic","topic","topic"]    

override func viewDidLoad() {
    super.viewDidLoad()
    // println(PFUser.currentUser())

    // 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 10
}

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


override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell


    cell.textLabel?.text = discoveryList[indexPath.row]
    cell.textLabel?.text?.capitalizedString
    cell.textLabel?.textAlignment = NSTextAlignment.Center



    // Configure the cell...

    return cell
}
// App Delegate

 // Create UIWindow within the screen boundaries.
    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)

    var nav1 = UINavigationController()
    var first = ccHome(nibName: nil, bundle: nil)
    nav1.viewControllers = [first]
    nav1.tabBarItem = UITabBarItem(title: "Home", image: UIImage(named:"house28.png"), tag: 1)

    var nav2 = UINavigationController()
    var second = ccDiscovery(nibName: nil, bundle: nil)
    nav2.viewControllers = [second]
    nav2.tabBarItem = UITabBarItem(title: "Discovery", image: UIImage(named:"three49.png"), tag: 1)

    var nav3 = UINavigationController()
    var third = ccPosting(nibName: nil, bundle: nil)
    nav3.viewControllers = [third]
    nav3.tabBarItem = UITabBarItem(title: "Add", image: UIImage(named:"add182.png"), tag: 1)

    var nav4 = UINavigationController()
    var four = ccNotification(nibName: nil, bundle: nil)
    nav4.viewControllers = [four]
    nav4.tabBarItem = UITabBarItem(title: "Notification", image: UIImage(named:"connection27.png"), tag: 1)

    var nav5 = UINavigationController()
    var five = ccProfile(nibName: nil, bundle: nil)
    nav5.viewControllers = [five]
    nav5.tabBarItem = UITabBarItem(title: "Profile", image: UIImage(named:"male12.png"), tag: 1)

    var tabs = UITabBarController()
    tabs.viewControllers = [nav1, nav2, nav3,nav4,nav5]

    self.window!.rootViewController = tabs;
    self.window?.makeKeyAndVisible();
1
Please add logs you see after crash. And also code of ccXxxx functions (methods?) - Max Komarychev
I'm using parse for the backend - James Moriarty

1 Answers

-1
votes

I believe the problem is with the code you use to get the UITableViewCell.

You are doing...

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell


    cell.textLabel?.text = discoveryList[indexPath.row]
    cell.textLabel?.text?.capitalizedString
    cell.textLabel?.textAlignment = NSTextAlignment.Center



    // Configure the cell...

    return cell
}

This only reuses an existing UITableViewCell, but does not create one. You need to add a condition to instantiate the new UITableViewCell if one does not already exist.

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
        var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as? UITableViewCell;
        if (cell == nil)
        {
            cell = SavedAppraisalTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: cellIdentifier);
        }

        // do some stuff

        return cell!;
}