2012-03-02 25 views
0

我有UITableView與自定義錶行。我需要的是有可能重新排列行。所以在viewDidLoad中我補充一下:iPhone:UITableView重排行按鈕

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [self.myTableView setEditing: YES animated: YES]; 
} 

還添加下一個方法:

- (BOOL)tableView:(UITableView *)tableView 
    canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
    return YES; 
} 


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


- (BOOL)tableView:(UITableView *)tableView 
    shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath { 
    return NO; 
} 


    - (BOOL)tableView:(UITableView *)tableView 
    canMoveRowAtIndexPath:(NSIndexPath *)indexPath { 
    return YES; 
} 

而且我設置背景色爲我定製的錶行:

- (UITableViewCell *)tableView:(UITableView *)tableView 
    cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
NSString *customTableRow = @"customTableRow"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: 
    customTableRow]; 
if (cell == nil) { 
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"customTableRow" 
     owner:self options:nil]; 
    if (nib.count > 0) { 
     cell = self.customTableRow; 
    } 
} 
cell.contentView.backgroundColor = [UIColor colorWithRed:(228.0f/255.0f) 
    green:237.0f/255.0f blue:244.0f/255.0f alpha:1.0]; 
return cell; 
} 

然後我跑我的應用程序和我有一個意想不到的看法:

enter image description here

所以我有兩個問題: 1.那爲什麼呢?重新排序按鈕不透明?
2.如何將該按鈕更改爲我的圖片?

回答

1

問題是你正在改變contentView的背景顏色。您是否嘗試過在-tableView:willDisplayCell: forRowAtIndexPath:中更改單元格本身的背景顏色?

+0

我沒有,但我會。那麼問題2呢? – Jim 2012-03-02 13:24:55

+0

你也許可以嘗試迭代單元格的子視圖並用自己的按鈕替換按鈕? – 2012-03-02 14:34:38

+0

Alexsander,對不起,但更改單元格的背景顏色(而不是其內容視圖)對單元格沒有任何可見的影響。此外,重新排序控件不包含在單元格的子視圖中。 – Sagiftw 2012-03-14 01:06:20