2013-02-23 23 views
4

我使用多行選擇選項進行tableview。所以,我使用了複選標記附件類型的動作。我還需要編輯/重命名所選行中的文本。桌面與檢查標記和詳細信息一起公開

基本上,我需要把左邊的複選標記(複選框)和細胞右側的詳細公開內容都用到。

下面的代碼是對號,我有,目前勾選出現在單元格的右側。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Navigation logic may go here. Create and push another view controller. 

    TSIPAppDelegate *appDelegate = (TSIPAppDelegate *)[[UIApplication sharedApplication]delegate]; 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    NSString *cellText = cell.textLabel.text; 
    if (cell.accessoryType==UITableViewCellAccessoryNone) 
    { 
     cell.accessoryType=UITableViewCellAccessoryCheckmark; 
     appDelegate.selectedFile = cellText; 
     if (prevSP!=indexPath.row) { 
     cell=[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:prevSP inSection:0]]; 
     cell.accessoryType=UITableViewCellAccessoryNone; 
     prevSP=indexPath.row; 
     } 
    } 
    else if (prevSP!=indexPath.row){ 
     cell.accessoryType=UITableViewCellAccessoryNone; 
    } 
} 

有什麼建議嗎?

當行選擇時,勾選要啓用/禁用和選定披露按鈕,它應該打開編輯所選行的新觀點。

+0

你可以請包括你有的代碼嗎?這會讓其他人更好地理解你現在擁有的東西。 – Jesse 2013-02-23 05:13:27

+0

@Jesse:我已經添加了代碼。請檢查。有關詳情披露,尚未撰寫。 – Arun 2013-02-23 05:22:02

+0

@Arun更好的方法是UITableViewCellAccessoryCheckmark而不是你都不能添加在每個單元和附件類型,因爲每個細胞 – Dany 2013-02-23 05:54:14

回答

1

這是我在一個已經用我的應用程序的示例代碼

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

{ 

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    cell.textLabel.text=[NSString stringWithFormat:@"%@",[cellarray objectAtIndex:indexPath.row]]; 
    cell.textLabel.textColor=[UIColor blackColor] ; 
    cell.textLabel.tag=indexPath.row; 
    cell.textLabel.font=[UIFont fontWithName:@"HelveticaNeue-Bold" size:15]; 
    // cell.textLabel.highlightedTextColor=[UIColor colorWithRed:242.0f/255.0f green:104.0f/255.0f blue:42.0f/255.0f alpha:1] ; 
    cell.selectionStyle=UITableViewCellSelectionStyleNone; 


} 

UIImageView *ima=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"tick.png"]]; 
ima.frame=CGRectMake(280, 15, 14, 14); 
ima.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin |UIViewAutoresizingFlexibleRightMargin; 

int row = [indexPath row]; 
//cell.accessoryType = (row == selectedRow) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone; 
cell.textLabel.textColor= (row == selectedRow) ? [UIColor colorWithRed:242.0f/255.0f green:104.0f/255.0f blue:42.0f/255.0f alpha:1] : [UIColor blackColor] ; 
if (row==selectedRow) { 

    [cell.contentView addSubview:ima]; 

} 

UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Background.png"]]; 
[tempImageView setFrame:tableView.frame]; 

tableView.backgroundView = tempImageView; 
[tempImageView release]; 
return cell; 
} 


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

selectedRow = [indexPath row]; // selected row is of type int declared in .h 

[tableView reloadData]; 


} 

此代碼將在整個的tableView只有一個對勾。您可以修改它以具有在

多個勾選希望這可以幫助 !!!

+0

看來,你是在該行的子視圖添加圖像月底開始有對號圖像的UIImagview。但是,我需要的是將複選標記的行存儲在數組中。並以某種方式允許選定行的文本的「重命名/編輯」。是否可以對文本進行「重命名」? – Arun 2013-02-23 07:02:13

+0

@Arun是的,你說你需要左側的複選標記和附件類型作爲rightside.and這是其中一個方法。並且您可以將文本標籤文本存儲在數組中用於重命名didSelectRowAtIndexPath – Dany 2013-02-23 07:13:24

+0

我只想詳細公開「重命名」的用途。啓用「重命名/編輯」選項的優先級高於保持左對齊或右對齊的優先級。謝謝。 – Arun 2013-02-23 07:41:41

2

accessoryType類型是枚舉UITableViewCellAccessoryType的,根據定義它不會接受多個值,因爲它不按位枚舉。所以,你必須選擇一個,並通過自定義代碼模擬另一個。

2

我推薦使用上的tableview的UITableViewCellAccessoryCheckmark附件類型,並加入了「詳細披露」按鈕,將細胞。不幸的是,你不能完全按照你的要求去做,但這是我找到的最乾淨的替代方法。