I have an int pageNumber setup like so @property (nonatomic, assign) int pageNumber;
which I am trying to pass between two view controllers.
It works the first time I tap a cell in the tableview, however if I tap a cell again the int does not get updated.
Any ideas? My code is below.
LeftMenuViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone"
bundle: nil];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
SoftwareCheckViewController *sc = [[SoftwareCheckViewController alloc] init];
if ([cell.textLabel.text isEqual: @"S:1 R:0"]) {
sc = [mainStoryboard instantiateViewControllerWithIdentifier: @"SoftwareCheckViewController"];
sc.pageNumber = 1;
}
else if ([cell.textLabel.text isEqual: @"S:1 R:1"]) {
sc = [mainStoryboard instantiateViewControllerWithIdentifier: @"SoftwareCheckViewController"];
sc.pageNumber = 2;
}
else if ([cell.textLabel.text isEqual: @"S:1 R:2"]) {
sc = [mainStoryboard instantiateViewControllerWithIdentifier: @"SoftwareCheckViewController"];
sc.pageNumber = 3;
}
[[NSNotificationCenter defaultCenter] postNotificationName:@"pageNumberNotification" object:self];
}
SoftwareCheckViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pageNumberMethod) name:@"pageNumberNotification" object:nil];
}
- (void)pageNumberMethod{
NSLog(@"pageNumber: %i", pageNumber);
}