0

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];
}
Rob
  • 415,655
  • 72
  • 787
  • 1,044
hanumanDev
  • 6,592
  • 11
  • 82
  • 146
  • this is your third question regarding the same issue. Please rephrase your previous questions, there is no need to ask the same thing over and over. – Stavash Feb 01 '13 at 13:58
  • Dude use a property in second view controller and set directly. or use delegate. When there is an easy way why you are doing like this? – Anil Varghese Feb 01 '13 at 14:08
  • 1
    is mainTable non-null when you're calling reloadData? – Will Jenkins Feb 01 '13 at 14:16
  • If both tables are visible, it seems inefficient to use notifications. – Rob Feb 01 '13 at 14:22
  • So what's the problem? You say the issue is how to reload the table -- you're doing that in this code. What's not working? – rdelmar Feb 01 '13 at 15:42

0 Answers0