I have a NSNotification
in viewController1
that sends the object:selectedTableString
when the didSelectRowAtIndexPath:
method is called in viewController1
.
The object:selectedTableString
object is then picked up in viewController2
. The console output is correct and the object is being picked up correctly. The issue I'm facing is how to reload ([mainTable reloadData];
) the tableView when the notification is received in viewController2
.
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
selectedTableString = cell.textLabel.text;
if (cell.accessoryType==UITableViewCellAccessoryNone)
{
cell.accessoryType=UITableViewCellAccessoryCheckmark;
if (prev!=indexPath.row) {
cell=[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:prev inSection:0]];
cell.accessoryType=UITableViewCellAccessoryNone;
prev=indexPath.row;
}
}
else{
cell.accessoryType=UITableViewCellAccessoryNone;
}
NSLog(@"selectedTableString is %@",selectedTableString);
NSLog(@"posting notification");
[[NSNotificationCenter defaultCenter] postNotificationName:@"TTSelectedList" object:selectedTableString];
}
then in viewController2
:
- (void)selectedList:(NSNotification*)notification
{
NSLog(@"received notification");
theString = [notification object];
NSLog(@"thestring is %@", theString);
// getting an NSString
selectedTableString = theString;
if ([selectedTableString isEqualToString:@"Italy"]) {
jsonStringCountry = @"http://***/v1/public/cities?country=it";
[mainTable reloadData];
}
else if ([selectedTableString isEqualToString:@"Spain"]) {
jsonStringCountry = @"http://***/v1/public/cities?country=es";
[mainTable reloadData];
}
else if ([selectedTableString isEqualToString:@"UK"]) {
jsonStringCountry = @"http://***/v1/public/cities?country=uk";
}
else if ([selectedTableString isEqualToString:@"Brazil"]) {
jsonStringCountry = @"http://***/v1/public/cities?country=br";
}
NSLog(@"from two table selectedTableString %@",selectedTableString);
[mainTable reloadData];
}