我有一個tableview,其中一個單元格應該顯示縮略圖圖像。但是,如果該圖像不可用(尚未拍攝),我想LIKE爲單元的accessoryView顯示相機UIBarButtonItem ...但是當我嘗試我平常的方法時,我得到'不兼容類型'的警告。有什麼方法可以在導航欄外使用這些項目嗎?是否有可能有一個UIBarButtonItem作爲單元accessoryView?
2
A
回答
5
由於UIBarButtonItem
不是UIView
,因此不可能直接使用UIBarButtonItem
作爲單元的附件視圖。
次優解決方案可能是使用UIToolbar
來保存您的UIBarButtonItem
。然後,您可以將UIToolbar
添加爲單元的附件視圖,但最終會出現UIToolbar
的不需要的輪廓。這SO answer解釋如何使透明UIToolbar
子類。這樣,你就不會看到工具欄的背景,但你也將失去UIBarButtonItem
的輪廓 - 它只會顯示白色的相機圖標:
UIToolbar *toolbar = [[TransparentToolbar alloc] init];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(someAction)];
toolbar.frame = CGRectMake(0, 0, 40, 30);
[toolbar setItems:[NSArray arrayWithObject:item] animated:NO];
cell.accessoryView = toolbar;
[item release];
[toolbar release];
0
我認爲這是不可能的。因爲它被稱爲BarButtonItem它只能進入一個欄。老辦法allthough工程:拍攝相機按鈕的屏幕截圖(只需將其添加到任何導航欄的截圖),截圖從屏幕截圖,添加一個普通的UIButton到您的單元格,並添加相機的圖像按鈕作爲backgroundimage
[button setBackgroundImage:[UIImage imageWithImage:@"camerabuttonpressed.png"] forState:UIControlStateHighlitedl];
相關問題
- 1. 是否有可能在960的單元內有一個網格?
- 2. 是否有可能有一個NSMutableDictionary作爲SingletonObject的屬性?
- 3. 是否有可能在Ada中有一個子包作爲單獨的編譯單元
- 4. 是否有可能爲單獨的href格式化單元格
- 5. 是否有可能爲一個單元測試,以斷定方法調用sys.exit()
- 6. 是否有可能通過一個char **作爲參數
- 7. 是否有可能在jqgrid單元格內有一個jQuery UI進度條
- 8. 是否有可能擁有一個屬性爲IEnumerable <T>?
- 9. 是否有可能爲所有活動提供一個GestureDetector?
- 10. 是否有可能一個POST
- 11. 是否有可能一個Parallel.ForEach
- 12. 是否有可能在Django中有一個類作爲模型字段?
- 13. 是否有可能擁有一個委託作爲屬性參數?
- 14. 是否有可能有一個構造函數的參數作爲類名C++?
- 15. 是否有可能在C++中有一個函數(-name)作爲模板參數?
- 16. 是否有可能有一個std :: list作爲C++結構的成員?
- 17. 是否有可能有一個Func鍵<bool>作爲while條件
- 18. 是否有可能有一個函數在另一個函數
- 19. 是否有可能爲一個元素設置多個數據選項鍵
- 20. 是否有可能有兩個curl_init
- 21. 是否有可能有多個STDIN流?
- 22. 是否有可能有多個viewEngine.viewExtension
- 23. 是否有可能爲每個新的一天有一個新的文件log4cXX
- 24. 在scala中,是否有可能只有兩個元素的Set?
- 25. 是否有可能在excel表單中有一個「重置表單」按鈕?
- 26. 是否有可能使用UINavigationViewController作爲ViewController的一部分
- 27. 是否有可能用js/dojo/jquery複製一個表單?
- 28. jquery - 是否有可能看到一個緩存元素是否隱藏
- 29. 是否有可能爲一系列renderscript動作使用一個分配?
- 30. 是否有可能在一個表單中有兩個「<input type = file>」?
感謝:使用
,並採取按鈕的截圖其按下時,保存它,並把它設置爲圖像的選中狀態您的UIButton。我遺漏了透明度,結果是一個不錯的按鈕。 –