2014-02-24 99 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

看到我的编辑,更新你的问题以及将来使用这个问题。如果你喜欢我的回答,请投票并接受它。 –