如何使用NSNotificationCenter发送数据并在收到数据后重新加载UITable?

时间:2013-02-01 13:56:26

标签: ios objective-c uitableview nsnotificationcenter

NSNotificationviewController1发送了object:selectedTableString didSelectRowAtIndexPath:viewController1中调用object:selectedTableString方法时。

然后在viewController2中选取[mainTable reloadData];个对象。控制台输出正确,正确拾取对象。我面临的问题是在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]; } )tableView。

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]; }

{{1}}

0 个答案:

没有答案