2012-04-25 132 views
1

您能否幫我解答。我需要執行編輯單元格。編輯應該看起來像: 當我按下barButtonItem(導航欄上的右邊那個)時,單元格的內容應該稍微向右移動,並且複選框應該出現。用戶應該能夠選擇幾個單元格並通過點擊相同的導航按鈕來提交編輯。 我試過使用標準編輯,但我不知道如何: - 選擇多個單元格,然後提交編輯 - 如何將提交操作設置爲navButton,而不是紅色刪除按鈕,它出現在每個選中的旁邊cell單元格的自定義編輯

+0

http://stackoverflow.com/questions/9101810/custom-uitableviewcell-uitableview-and-allowsmultipleselectionduringediting訪問此refence .. – Nit 2012-04-25 13:02:10

回答

3

多選被視爲編輯風格之一。因此,爲了使細胞多選擇,在你的UITableViewDelegate實現這個:

-(UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath { 
    ... 
    return 3; 
} 

「3」在這裏是指多選。其結果是這樣的:

enter image description here

要獲得所選行,調用

-indexPathsForSelectedRows method on the table view. 
NSArray* selectedRows = [tableView indexPathsForSelectedRows]; 

如果你不喜歡紅色的對勾,您可以使用無證multiselectCheckmarkColor屬性來改變它。不幸的是,它必須應用在整個桌子上。

tableView.multiselectCheckmarkColor = [UIColor blueColor]; 

淡藍色的背景顏色,除非你子類或分類

UITableViewCell and override the -_multiselectBackgroundColor method, like this: 
-(UIColor*)_multiselectBackgroundColor { return [UIColor yellowColor]; } 

希望不能改變,這將幫助你..

+0

謝謝這正是我需要的。你還可以回答當我按下編輯時如何正確佈置躺在我的單元格上的自定義視圖(標籤,按鈕,imgView等)? (現在,當我按下編輯時,一些視圖正在相對於單元格視圖移動)但是我需要這些內容被壓縮並且不會移動到可見邊界之後。 – Stas 2012-04-25 13:51:57

+0

我現在很忙,有些工作會給你和明天,因爲我有一些工作在你的方案。 – Nit 2012-04-25 13:54:03

+0

好的,我會等你的回答.... – Stas 2012-04-26 12:39:25

3

尼特的回答有一個bug。

代碼

tableView.multiselectCheckmarkColor = [UIColor blueColor]; 

應該這樣寫:

[tableView setValue:[UIColor blueColor] forKey:@"multiselectCheckmarkColor"]; 

我想這個對的Xcode 4.5和它的工作。

+0

謝謝,會考慮到它 – Stas 2013-01-19 17:48:58

0

如果它仍然相關,請注意,在iOS 7+上,您可以簡單地使用UITableView的tintColor屬性 - 這將設置複選標記顏色。

相關問題