【问题标题】:didSelectRowAtIndexPath to assign valuesdidSelectRowAtIndexPath 分配值
【发布时间】:2014-02-24 15:48:09
【问题描述】:

我在一个简单的事情上遇到了问题。 我有一个(它不是 SplitViewController)ViewController,里面有一个 TableView 对象。 我希望当用户单击表格中的一行时,我右侧的标签会相应更改。

我想要更改的标签(右侧带有“Nome do Vinho”文字)

@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];

填充表格视图

- (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 方法上制作的,但我不知道如何。 如果我忘记发布重要的内容,请告诉我。

【问题讨论】:

  • 能否请您发布您的-didSelectRowAtIndexPath 方法?

标签: objective-c ipad uitableview didselectrowatindexpath


【解决方案1】:

你不想把右边的标签改成单元格文字吗?

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

如果你不想要评论中所说的淡入淡出动画,也许这可以让你开始:xCode ios5: How to fade out a label text after an interval?

【讨论】:

  • 感谢@Jonathan 完美。顺便说一句,有一种方法可以改变文本并产生一些效果吗?也许是淡入或什么?
  • 查看我的编辑,更新您的问题以及将来使用此问题。如果您喜欢我的回答,请投票并接受它。
猜你喜欢
  • 2011-02-26
  • 2011-06-22
  • 2023-03-24
  • 1970-01-01
  • 2012-01-14
  • 1970-01-01
  • 1970-01-01
  • 2023-04-01
  • 2015-07-02
相关资源
最近更新 更多