我有一個iPhone應用程序,它有一個UITabBarController
,其中包含多個UITableViews
。我需要能夠將項目添加到每個UITableView
(每個標籤中),但是我的Google-fu令我失望,使我無法找到如何在右上角放置「+」按鈕的示例,導航項目。這個「+」按鈕將打開一個子視圖來輸入新項目的信息,一旦我得到按鈕出現,我應該能夠處理這些信息。我想以編程方式進行此操作,而不是通過IB。有人能夠啓發我嗎?iPhone UITableView
1
A
回答
1
你可以在這樣的導航欄右側設置按鈕:
self.navigationItem.rightBarButtonItem = button;
的按鈕將需要一個的UIBarButtonItem。您可以創建的UIBarButtonItem,並添加一個目標時,按下按鈕,像這樣:
button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(method:)];
目標和行動(選擇當按下它來調用)是可以改變的,無論你需要的。
一起,在一條線,它看起來像這樣:
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(method:)];
這應該是一切必要創建一個添加按鈕,並把它添加到navigationItem。
以前的答案,也談到了使用一個UIButton低於:
這是你如何創建一個普通的 按鈕,如果必要的話:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button addTarget:self action:@selector(addButtonPressed)
forControlEvents:UIControlEventTouchUpInside]。
這將調用 類中的addButtonPressed類,在該類中按下時創建按鈕 。您可以將 目標和選擇器更改爲 需要的任何值。
合:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button addTarget:self action:@selector(addButtonPressed)
forControlEvents:UIControlEventTouchUpInside]; self.navigationItem.rightBarButtonItem = button;
希望這會有所幫助!
0
將UIBarButtonItem設置爲self.navigationIten.rightBarButtonItem並處理其操作。
要添加行,請使用tableView的insertRowAtIndexPath方法。
相關問題
- 1. 從NSMutableArray UITableView iPhone
- 2. iPhone UITableView泄漏
- 3. iPhone - 通用UITableView
- 4. iPhone - iAds in UITableView
- 5. iPhone UITableView古怪
- 6. 的UITableView在iPhone
- 7. iPhone分組UITableView
- 8. 誤差的UITableView iphone
- 9. iPhone - UITableView數據源?
- 10. 如何從UITableView iphone獲取UITableView IndexPath?
- 11. iPhone的UITableView - 可見細胞
- 12. UITableview背景顏色-iphone
- 13. iphone UITableVIew(基於導航)
- 14. iPhone - 滾動UITableView索引
- 15. iPhone Dev,UITableView背景顏色
- 16. 地址簿+ UITableView索引iPhone
- 17. UITableView中的iPhone多列
- 18. iPhone - >用UITableViewController代替UITableView
- 19. iphone - UITableView滾動問題
- 20. iPhone UITableView與多個部分
- 21. iphone uitableview - 鏈接問題?
- 22. iPhone UITableView分頁結果
- 23. iPad/iPhone上的UITableView像Mail.app
- 24. UITableview部分覆蓋在iPhone?
- 25. iphone UITableView動態創建
- 26. iPhone UITableView +旋轉=消失表?
- 27. iPhone +調整大小UITableView
- 28. iphone,在UITableView中的UITextField
- 29. iPhone SDK:從SQLite加載UITableView
- 30. 沒有結果 - UITableView iPhone
我相信你的答案在這裏:[在UITableView中使用插入行](http://stackoverflow.com/questions/1470898/using-insert-rows-in-a-uitableview)。我通過在谷歌搜索「uitableview add row」找到了這個。 – PengOne 2011-06-11 20:37:11