首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xcode 6.3与Swift与tableview的崩溃

Xcode 6.3与Swift与tableview的崩溃
EN

Stack Overflow用户
提问于 2015-03-03 18:32:13
回答 1查看 750关注 0票数 0

在app委托中设置UItabbar之后,我遇到了这个问题。

问题是:

  1. 该应用程序只有在按下“发现”选项卡后才会崩溃。
  2. 家庭+添加+配置文件ViewControllers是黑色的。

提前谢谢你

代码语言:javascript
复制
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();
EN

回答 1

Stack Overflow用户

发布于 2015-03-03 20:13:56

我认为问题在于您用于获取UITableViewCell的代码。

你在做..。

代码语言:javascript
复制
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
}

这只会重用现有的UITableViewCell,但不会创建一个。如果新的UITableViewCell还不存在,则需要添加一个条件来实例化它。

代码语言:javascript
复制
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!;
}
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28839328

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档