iOS - UIVIewController中的UITableView不显示所有行[Swift] [英] iOS - UITableView in UIVIewController doesn't display all rows [Swift]

查看:128
本文介绍了iOS - UIVIewController中的UITableView不显示所有行[Swift]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UIViewController 中遇到了我的 UITableView 的错误。
我会试着解释一下情况和我的问题。

I'm facing a bug with my UITableView in UIViewController. I'll try to explain what's the situation and my problem.

我有一个 TabBarController 哪个视图是 UIViewController ,带有 UITableView 。我不使用 UITableViewController 因为我的 UIViewController 上有一些细节控件。

I have a TabBarController which a view is a UIViewController with a UITableView. I don't use a UITableViewController because I have some specifics controls on my UIViewController.

所以,当我的 UIViewController 不是我的 TabBarController 的孩子时,一切都是好的:所有行都显示正确。

So, when my UIViewController isn't a child of my TabBarController, everything is okay : all rows are displayed correctly.

但是,当我将 UIViewController 设置为我的<$的孩子时c $ c> TabBarController ,我有这个错误:只显示一些行(在所有情况下都显示一个超过3米)。

But, when I set my UIViewController as a child of my TabBarController, I have this bug : only some rows are displayed (one over threem exactly, in all scenarios).

我只是不明白发生了什么。我的代码似乎有效,但只有当我的 UIViewController 不是我的 TabBarController 的子代。

I just don't understand what's happening. My code seems working, but only when my UIViewController isn't a child of my TabBarController.

在这种情况下还有另一种方法可以添加吗?

Is there another method to add in this case ?

我的代码是 UIViewController

class ProfileController: UIViewController, UITableViewDataSource, UITableViewDelegate {

    @IBOutlet weak var tableChallenges: UITableView!
    @IBOutlet weak var profileTabs: UISegmentedControl!

    var pageViewController : UIPageViewController!

    override func viewDidLoad() {
        super.viewDidLoad()

        self.tableChallenges.dataSource = self
        self.tableChallenges.delegate = self

        self.tableChallenges.reloadData()

    }

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

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 5
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCellWithIdentifier("challengeCustomCell", forIndexPath: indexPath) as! ChallengeCustomCell

        switch(self.profileTabs.selectedSegmentIndex) {
            case 0:
                cell.challengeSuccededOrFailedImage.hidden = true
            break

            case 1:
                cell.challengeSuccededOrFailedImage.hidden = false
                cell.challengeSuccededOrFailedImage.image = UIImage(named: "challenge-succeded")
            break

            case 2:
                cell.challengeSuccededOrFailedImage.hidden = false
                cell.challengeSuccededOrFailedImage.image = UIImage(named: "challenge-failed")
            break

            case 3:
                cell.challengeSuccededOrFailedImage.hidden = true
            break

            default: break

        }

        return cell
    }

    @IBAction func selectedItemChanged(sender: AnyObject) {
        self.tableChallenges.reloadData()
    }
}

提前感谢您的回答! :)

Thanks in advance for your answers ! :)

推荐答案

很抱歉很长时间没有反馈。

Sorry about the long time without feedback.

我终于找到了解决问题的方法。我在 UINavigationController 中嵌入了 UIViewController ,其中包含 UITableView 。经过一些研究后,这个案例似乎是一个很好的等级。

I have finally found a solution to my problem. I embedded my UIViewController which contains the UITableView in a UINavigationController. After a few researchs, it seems to be the good hierarchy for this case.

希望这有助于有人帮忙。 :)

Hope this will help somebody helse. :)

这篇关于iOS - UIVIewController中的UITableView不显示所有行[Swift]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆