2014-02-24 49 views
0

我有一個問題,我猜,簡單的事情。 我有一個(它不是一個SplitViewController)ViewController與其中的一個TableView對象。 我希望當用戶點擊表格中的一行時,右側的標籤會相應更改。didSelectRowAtIndexPath來分配值

My screen - ViewController with a TableView. It is NOT a SplitViewController

我的標籤(與文本「諾姆都溫霍」右邊),我想改變

@property (weak, nonatomic) IBOutlet UILabel *rotuloDetalhesLabel; 

我填充的TableView與此代碼。 我在viewDidLoad方法上創建對象,並放入一個名爲「vinhos」的NSArray。

// Create object 
Vinho *vinho1 = [Vinho new]; 
vinho1.rotulo = @"Adega de Borda Premium"; 

Vinho *vinho2 = [Vinho new]; 
vinho2.rotulo = @"Adega de Borda Premium 2"; 


// Populate the NSArray with the objects that I create before 
vinhos = [NSArray arrayWithObjects: vinho1, vinho2, nil]; 

填充的TableView

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Configura a Cell 
    static NSString *CellIdentifier = @"TableCell"; 
    TableCell *cell = (TableCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     cell = [[TableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    Vinho *vinho = [vinhos objectAtIndex:indexPath.row]; 

    // rotuloLabel is the Label of the row 
    cell.rotuloLabel.text = vinho.rotulo; 

    return cell; 
} 

我想,它是由在didSelectRowAtIndexPath方法的方法,但我不知道怎麼辦。 如果我忘記發佈重要內容,請告訴我。

+0

能否請您發表您的'-didSelectRowAtIndexPath'方法? – Mischa

回答

0

您是否想要更改單元格文本右側的標籤?

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    Vinho *vinho = [vinhos objectAtIndex:indexPath.row]; 
    NSString *cellRotuloText = vinho.rotulo; 
    rotuloDetalhesLabel.text = cellRotuloText; 
} 

如果您wan't的動畫漸變如你所說的評論,也許這可以讓你開始:xCode ios5: How to fade out a label text after an interval?

+0

謝謝@Jonathan完美的作品。 通過外出,有一種方法來改變文本有一些效果?也許淡入或什麼東西? –

+0

看到我的編輯,更新你的問題以及將來使用這個問題。如果你喜歡我的回答,請投票並接受它。 –