سؤال

I'm having problems with a , I guess, simple thing. I have a (It is NOT a SplitViewController) ViewController with a TableView object in it. I want that when the users click a row in a table, my label on the right side change appropriately.

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

My label (with the text "Nome do Vinho" on the right) that i want to change

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

I populate the TableView with this code. I create the objects on viewDidLoad method and put in a NSArray called "vinhos".

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

Populating the 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;
}

I guess that it is made on didSelectRowAtIndexPath method but I dont know how. If I forget to post something important just tell me.

هل كانت مفيدة؟

المحلول

Do you wan't to change the label on the right to the cell text?

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

If you wan't the fade animation as you said in the comment, maybe this could get you started: xCode ios5: How to fade out a label text after an interval?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top