2016-07-22 92 views
0

我的nav_bar應該在右側顯示logged_in用戶的圖片,然後單擊它應該會打開一個配置文件屏幕。無法將遠程圖像添加到ProMotion中的nav_bar按鈕

對於尚未上傳個人資料圖片的新用戶,由於它使用的是本地佔位符圖片,因此它工作正常,但當Auth.current_user["image"]包含指向用戶的REMOTE個人資料圖片的網址時,該圖片不再有效。

def on_load 

image_view = UIImageView.alloc.initWithFrame(CGRectMake(0, 0, 50, 50)) 
image_view.contentMode = UIViewContentModeScaleAspectFit 
image_view.setImageWithURL(Auth.current_user["image"]) 

set_nav_bar_button :right, 
    image: Auth.current_user["image"].nil? ? image.resource("icon_user_50x50.png") : image_view, 
    action: :open_profile 

end 

當遠程圖像存在時,此代碼無法正常工作。它顯示圖像,但點擊/點擊時沒有任何反應。

如果我交流這個行:

image: Auth.current_user["image"].nil? ? image.resource("icon_user_50x50.png") : image_view, 
for this one: 

image: Auth.current_user["image"].nil? ? image.resource("icon_user_50x50.png") : image.from_view(image_view), 

攻/現在點擊的作品,但沒有圖像顯示。

任何幫助,將不勝感激。

回答

0

當在nav_bar中使用自定義UIImageView作爲按鈕時,該按鈕會失去點擊功能。您可以通過添加以下幾行來恢復:

image_view.setUserInteractionEnabled(true) 
image_view.addGestureRecognizer(UITapGestureRecognizer.alloc.initWithTarget(self, action: :open_profile))