我正在尝试(徒劳)从另一个View Controller MasterViewController
重新加载SitesViewController
中的tableView。我在SitesViewController
:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger row = [[self tableView].indexPathForSelectedRow row];
//NSArray *appcell = [sitesMenu objectForKey:@"Table"];
NSLog(@"AppCell %@", sitesMenu);
NSDictionary *entry = [sitesMenu objectAtIndex:row];
self.siteid = [entry objectForKey:@"SITEID"];
NSLog(@" sample SiteView %@", siteid);
NDSClassMasterViewController *detailControllerTwo = [[NDSClassMasterViewController alloc] init];
detailControllerTwo.globalid = siteid;
NSLog(@"message %@", detailControllerTwo.globalid);
[detailControllerTwo fetchTweets];
dispatch_async(dispatch_get_main_queue(), ^{
[detailControllerTwo.tableView reloadData];
NSLog(@"%@", detailControllerTwo);
});
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
*/
}
以及我正在调用的方法的代码:
- (void)fetchTweets
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *siteurl = [[NSString alloc] initWithFormat:@"http://adhoc.nyxtek.co.za/spfjsonws/default2.aspx?siteid=%@", globalid];
NSData* data = [NSData dataWithContentsOfURL:
[NSURL URLWithString: siteurl]];
NSError* error;
menuItems = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:&error];
NSLog(@"%@", menuItems);
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
});
}
我甚至已将重载代码添加到SiteViewController didSelectRow方法中。
我已经读过我应该为它添加一个属性并进行综合但是我已经尝试了但不确定如何为UITableView添加一个属性来引用现有属性。
运行fetchTweets代码,但TableView不会重新加载。
任何帮助都将不胜感激。
修改
这是我在单元格中加载项目的TableView代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"TweetCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//NSString *name = [[[menuItems objectForKey:@"Table"] objectAtIndex:0] objectForKey:@"MENUID"];
NSDictionary *tweet = [[menuItems objectForKey:@"Table"] objectAtIndex:indexPath.row];
//NSLog(@"%@", tweet);
NSString *text = [tweet objectForKey:@"MENUDESC"];
NSString *name = [tweet objectForKey:@"MENUDESC"];
NSLog(@"TEST 1%@", text);
cell.textLabel.text = text;
cell.detailTextLabel.text = [NSString stringWithFormat:@"by %@", name];
return cell;
}
答案 0 :(得分:0)
为什么不在视图控制器中编写一个包含将重新加载数据的代码的函数,而不是通过属性公开表视图?
E.G。而不是:
[detailControllerTwo.tableView reloadData];
在MasterViewController中声明一个类似于:
的方法- (void) updateTable
{
// tableView is declared as an IBOutlet
[tableView reloadData];
}
然后你可以用:
来调用它dispatch_async(dispatch_get_main_queue(), ^{
[detailControllerTwo updateTable];
NSLog(@"%@", detailControllerTwo);
});