我有两个由 segue 连接的 ViewController,第一个是 Sub View,第二个是 Sub Tabela 我想将该表中选定行的值从我的第一个 View Controller 传递到我的第二个 View Controller ,这样我就可以定义他的标题。 这是代码。
SubView.m(我的第一个 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(我的第二个 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);
}
请帮忙!
最佳答案
我认为您没有正确传递数据,看起来您正在 didSelectRowAtIndexPath
中创建一个对象并将数据传递到其中,然后丢弃该对象。你需要做的是调用这个:
[self performSegueWithIdentifier:<#(NSString *)#> sender:self];
改变屏幕然后像这样传递数据是prepareForSegue
回调
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
SubTabela *vc = (SubTabela *)segue.destinationViewController;
vc.tituloTabela = linhaSelecionada;
}
关于ios - 之间传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21237894/