未调用 UITableView 方法 cellForRowAtIndexPath [英] UITableView method cellForRowAtIndexPath not called

查看:28
本文介绍了未调用 UITableView 方法 cellForRowAtIndexPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 UITableView 没有显示任何数据.我认为问题在于:

My UITableView isn't showing any data. I think the problem is in:

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell?`

这是我的代码:

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell? {
    // Configure the cell...
    let cellId: NSString = "Cell"
    var cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(cellId) as UITableViewCell

    if let ip = indexPath {
        //var data: NSManagedObject = myList[ip.row] as NSManagedObject
        //cell.textLabel.text = data.valueForKey("name") as String
        cell.textLabel.text = "Hi"
    }
    return cell
}

我在 youtube 上看过使用此代码的教程,但我无法让它工作.

I've seen tutorials on youtube that use this code, but I can't get it to work.

首先我认为这是我的阵列的问题,但是当我将文本放入其中时它仍然没有显示任何内容.

First I fought it was a problem with my array, but when i just put text in it it still doesn't show anything.

我正在运行 Xcode6 beta 3,但是这段代码在 beta 2 中运行得非常好.

I'm running Xcode6 beta 3, but this code did run perfectly fine in beta 2.

我没有任何警告或错误消息.

I don't have any warning or error messages.

我查找了我的其他一些 Swift 项目,我在那里获得了相同的功能,并且它在 2 周前起作用了,但现在它也不起作用了.也许这是 Xcode6 beta 3 问题?

I looked up some other Swift projects of me, I got the same function in there and it worked 2 weeks ago but now it also doesn't work. Maybe this is a Xcode6 beta 3 issue?

我的类是 UITableViewController 类型.

在更新到 xCode 6 beta 3 后,我浏览了 Apple 开发者论坛并看到了相关问题,因此 xCode 6 beta 3 可能存在问题!

I was looking through the Apple developer forums and saw related issues after updating to xCode 6 beta 3, so it's likely a problem with xCode 6 beta 3!

该方法不会被调用.

推荐答案

知道了!

遇到了同样的问题 - 我还在 uiviewcontroller 中添加了一个 tableview,但它也不起作用,但我现在知道问题所在了.

Had the same problem - I also have added a tableview into a uiviewcontroller and it also not worked, but I know the problem now.

如果您在界面构建器上添加 tableview 并单击添加缺少的约束",它将添加无法一起工作的约束.

If you add the tableview on interface builder AND click after that "Add Missing Constraints", it'll add constraints that can't work together.

在我的位置上,我的整个 uiview 上都有 tableview,单击添加缺少的约束"后,它会在此处添加:

At my position I had the tableview on my whole uiview and after click on "Add Missing Constraints", it will add this here:

现在,如果您删除尾随或前导对齐方式之一,它将起作用 - cellforrowatindexPath 将被调用!不知道为什么会这样,但它会起作用.

And now if you delete one of the Trailing or Leading Alignments, it will work - cellforrowatindexPath will get called! Don't know why it is like that, but it will work.

希望能帮到你.

这篇关于未调用 UITableView 方法 cellForRowAtIndexPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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