2013-10-25 59 views
1

我想在RubyMotion項目中混合運動佈局和茶杯。我創建了一個例子視圖助手來說明我的問題:混合運動佈局和茶杯

module Teacup::Layout 

    def example(name, options = {}) 

    subview UIView, name do 
     subview UILabel, "#{name}_label".to_sym, text: options[:label] 

     auto do 
     horizontal "|-[#{name}_label]-|" 
     end 
    end 
    end 
end 

當我打電話example(:example), text: "Test"一個layout塊裏面,我的代碼拋出以下異常:

(main)> 2013-10-25 13:40:45.989 rui[55552:80b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse constraint format: 
example_label is not a key in the views dictionary. 
H:|-[example_label]-| 

如果我忽略了運動佈局代碼並檢查意見,example_label視圖是example視圖的子項。這裏發生了什麼?

+0

也許嘗試使用字符串而不是符號?我不是自動佈局專家。 –

+0

不幸的是,這並沒有成功。 – LandonSchropp

+0

我認爲這段代碼應該可以工作,明天我會玩吧! :-) – colinta

回答

0

在了茶杯的文檔,它說:

# if you need to apply these to a different view, or if you want to assign 
# different names to use in the ASCII strings 
# auto(layout_view=self.view, layout_subviews={}, &layout_block) 

由於創作的這些意見的「動態」的性質和佈局(運動佈局)的一個子視圖,而不是一個被佈局(茶杯),但它可能會變得困惑,儘管子視圖和佈局相似。

無論如何,使用文檔中的建議嘗試非常具體地瞭解哪些視圖會進入auto塊,那麼對於佈局中的內容應該沒有歧義。