Reputation: 7540
It is simple, but I really don't know why it always gives me null.
- FirstViewcontroller:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[_tableView deselectRowAtIndexPath:indexPath animated:YES];
SubViewViewController *viewTwo = [[SubViewViewController alloc] initWithNibName:@"SubViewViewController" bundle:[NSBundle mainBundle]];
viewTwo.queryValue = [NSString stringWithFormat:@"%d",indexPath.row];
[self.navigationController pushViewController:self.subViewController animated:YES];
}
- SecondViewcontroller.h:
NSString *queryValue;
@property (nonatomic, retain) NSString *queryValue;
- SecondViewcontroller.m:
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"%@", self.queryValue);
}
Upvotes: 0
Views: 127
Reputation: 7343
You are pushing self.subViewController
but you are passing the string to viewTwo
. These are 2 different objects. Use this line instead:
[self.navigationController pushViewController:viewTwo animated:YES];
Upvotes: 1
Reputation: 5268
Please use the following code
- FirstViewcontroller:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[_tableView deselectRowAtIndexPath:indexPath animated:YES];
self.subViewController = [[SubViewViewController alloc] initWithNibName:@"SubViewViewController" bundle:[NSBundle mainBundle]];
viewTwo.queryValue = [NSString stringWithFormat:@"%d",indexPath.row];
[self.navigationController pushViewController:self.subViewController animated:YES];
}
- SecondViewcontroller.h:
@property (nonatomic, retain) NSString *queryValue;
- SecondViewcontroller.m:
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"%@", self.queryValue);
}
Upvotes: 0
Reputation: 12671
In your code you are doing wrong you should initialize the viewController which you are pushing to the navigationController, you are initializing viewTo
but you are pushing self.subViewController
.
should be initializing like this;
self.subViewController= [[SubViewViewController alloc] initWithNibName:@"SubViewViewController" bundle:[NSBundle mainBundle]];
Upvotes: 3
Reputation: 9143
change here
[self.navigationController pushViewController:viewTwo animated:YES];
Do change in SecondViewcontroller.h file
{
NSString *queryValue;
}
@property (nonatomic, strong) NSString *queryValue;
Upvotes: 1