سؤال

I have two ViewControllers conected by a segue, the first is Sub View and the second is Sub Tabela I want to pass a value from the selected row in that table from my first view controller to my second view controller, so i can define his title. Here is the code.

SubView.m (My first ViewController)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // _vinhoArray is the array that I populate the TableView
    NSString *selectedRow = [_vinhoArray objectAtIndex:indexPath.row];
    // Sub Tabela is the name of Second View
    SubTabela *subTabela = [[SubTabela alloc] init];
    // tituloTabela is a NSString in my Second View
    subTabela.tituloTabela = linhaSelecionada;

    // Here i get the Right value
    NSLog(@"value %@", subTabela.tituloTabela);

}

SubTabela.h (My second ViewController)

@property (nonatomic, strong) NSString *tituloTabela;

SubTabela.m

@synthesize tituloTabela;

- (void)viewDidLoad
{

    [super viewDidLoad];

    self.title = tituloTabela;

    // Here i get the a Null value
    NSLog(@"value %@", tituloTabela);

}

Please Help!

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

المحلول

I don't think your passing your data in correctly, it looks as though you are creating an object inside your didSelectRowAtIndexPath and passing the data into that, then discarding this object. What you need to do is call this:

[self performSegueWithIdentifier:<#(NSString *)#> sender:self];

to change the screen and then pass the data like this is the prepareForSegue callback

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    SubTabela *vc = (SubTabela *)segue.destinationViewController;
    vc.tituloTabela = linhaSelecionada;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top