我有一个NSNotification
inviewController1
发送调用方法object:selectedTableString
时的didSelectRowAtIndexPath:
in viewController1
。
object:selectedTableString
然后在 中拾取该对象viewController2
。控制台输出正确,物体被正确拾取。我面临的问题是如何在[mainTable reloadData];
收到通知时重新加载()tableView 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];
}
然后在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];
}