【问题标题】:ProMotion Styling Table Cells with Teacup带茶杯的 ProMotion 造型表单元格
【发布时间】:2013-11-18 19:11:19
【问题描述】:

我已经到处寻找 Google 的答案,但没有任何乐趣。我想做的是混合搭配 Teacup 和 ProMotion 用于桌子。整个表很简单。只需将其添加到 table_data 方法中数据元素的哈希中即可。

stylename: :leg_cell

-和-

Teacup::Stylesheet.new :main_screen do
  style :leg_cell,
    backgroundColor: UIColor.colorWithRed(238, green:238, blue:238, alpha: 1),
    textColor: UIColor.greenColor
  style UITableViewLabel,
    textColor: UIColor.greenColor
end

用于样式表。但是...UITableViewLabel 被忽略了,还有这个:

Symbiote 告诉我这是一个 UITableViewLabel,但我没有找到设置样式的方法。此外,Teacup 还提供这些整洁的服务:

layout do
  # things here to add styled subviews

与在 ProMotion 中添加东西的子视图非常相似的东西。这些如何(以及)共存?

关于如何将 tableview 标签设置为绿色的任何提示?甚至可能使用 TeaCup 添加一些自定义 UILabel?

注意:我知道绿色很糟糕,但我使用它只是为了证明我的元素样式正确。一旦我得到正确的样式,我会选择更有品味的东西。

谢谢!

【问题讨论】:

    标签: uitableview rubymotion teacup


    【解决方案1】:

    我建议继承 PM::TableViewCell(它是 UITableViewCell 的子类)并在其中应用您的 Teacup 样式。

    class MyTableViewCell < PM::TableViewCell
      attr_accessor :mileage_label
    
      stylesheet :main_screen
      def layoutSubviews
        layout do
          # Subviews
          # Apply `self.mileage_label` to your UILabel here.
        end
        restyle! # May be necessary?
      end
    end
    
    class MyScreen < PM::TableScreen
      def table_data
        [{
          cells: [{
            cell_class: MyTableViewCell,
            title: "whatever",
            properties: {
              mileage_label: "My mileage label",
            }
          }]
        }]
      end
    end
    

    【讨论】:

    • 所以在这种情况下,假设我的PM::TableViewCell 有一个名为mileage_labelUILabel 子视图。如何在 table_data 哈希中指定 mileage_label 的文本?
    • 更新了我的代码示例以展示如何。您添加一个attr_accessor,然后可以在您的 table_data 哈希中引用它。
    • 我正在尝试类似的东西,但收到此错误"In NavigationScreen#table_data, you should set :event_name, :today in a `properties:` hash. See TableScreen documentation."。我正在使用 event_name 和 today 而不是 milage_label 但其他方面基本相同。
    • 另外,当我尝试添加样式表行时,编译失败并出现此错误Terminating app due to uncaught exception 'NoMethodError', reason: 'undefined method `stylesheet' for EventCell:Class (NoMethodError)。这是我的班级声明行:class EventCell &lt; PM::TableViewCell.
    • @Dan - 我更新了示例。您现在想在新版本的 ProMotion 中使用 properties 哈希。不确定第二个错误是什么——请提出问题!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多