NSNotification
中viewController1
发送了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}}