ios - RubyMotion UITableView 数据源未正确返回

标签 ios rubymotion

我是 RubyMotion 的新手。使用此 Controller :

class LectureController < UIViewController


    def viewDidLoad
        super

        self.view.backgroundColor = UIColor.whiteColor

        @lectures ||= []

        Lecture.get() do |success, lectures|
            if success
                @lectures = lectures
                p "Received #{@lectures.length} lectures"
                @table.reloadData
            else
                App.alert("OOPS!")
            end
        end


        @table = UITableView.alloc.initWithFrame(self.view.bounds)
        self.view.addSubview @table
        @table.dataSource = self


        def tableView(tableView, numberOfRowsInSection: section)
            @lectures.count
        end

        def tableView(tableView, cellForRowAtIndexPath: indexPath)
            @reuseIdentifier ||= "CELL_IDENTIFIER"

            cell = tableView.dequeueReusableCellWithIdentifier(@reuseIdentifier) || begin
                UITableViewCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier: @reuseIdentifier)
            end

            cell.textLabel.text = @lectures[indexPath.row].name

            cell
        end


    end

    def initWithNibName(name, bundle: bundle)
        super
        self.title = "Lectures"
        self
    end

end

我遇到以下错误消息:

Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'UITableView dataSource must return a cell from
tableView:cellForRowAtIndexPath:'

据我所知,cellForRowAtIndexPath 应该返回一个单元格。我不明白为什么它不起作用。

任何帮助将不胜感激。

最佳答案

您的两个 tableView 方法嵌套在 viewDidLoad 方法下。它们应该被移出,成为主 LectureController 类的一部分。

在典型的 Ruby 类中,您可能可以摆脱这种情况(其中调用 viewDidLoad 方法动态定义其他方法),但它在 RubyMotion 中不起作用,因为代码已转换/编译。

关于ios - RubyMotion UITableView 数据源未正确返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14293680/

相关文章:

ios - RubyMotion >> 如何将变量转换为特定类型?

iphone - iPhone 热图

ios - 代号一中的 DNS 问题

ruby - 使用气泡膜 : How to formulate get with custom headers?

ios - 我可以将 kindle-highlights gem 与 RubyMotion 一起使用吗

ios - 在 RubyMotion 中捕获 UIView

ios - 无法识别的选择器发送到 UIImage?

ios - 为什么必须复制 block 而不是保留 block ?什么时候不需要复制 block ?

objective-c - Facebook 连接登录对话框崩溃的应用程序

iphone - 检测何时显示 MapView 瓦片