Objective c 为TableView重新加载数据未加载cellForRowAtIndexPath或行计数
我正在尝试(徒劳地)从另一个视图控制器Objective c 为TableView重新加载数据未加载cellForRowAtIndexPath或行计数,objective-c,xcode,uitableview,reloaddata,Objective C,Xcode,Uitableview,Reloaddata,我正在尝试(徒劳地)从另一个视图控制器SitesViewController在MasterViewController中重新加载tableView。我在SitesViewController中使用此代码: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSInteger row = [[self tableView].indexPathForSel
SitesViewController
在MasterViewController
中重新加载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];
*/
}
我甚至在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;
}
与其通过属性公开表视图,为什么不在视图控制器中编写一个函数,其中包含重新加载数据的代码 例如,代替:
[detailControllerTwo.tableView reloadData];
在MasterViewController中声明如下所示的方法:
- (void) updateTable
{
// tableView is declared as an IBOutlet
[tableView reloadData];
}
然后你可以用以下方式来称呼它:
dispatch_async(dispatch_get_main_queue(), ^{
[detailControllerTwo updateTable];
NSLog(@"%@", detailControllerTwo);
});
谢谢,我会试试的!我添加了:ibuitableview*tableView;到MasterViewController.h文件。我还在debug中一步一步地记录了代码,除了重新加载不会更新表之外,其他每一行都在该方法中运行。在“
reloadData
”之前添加这一行:“if(tableView==NULL)NSLog(@“为什么我的表视图出口没有连接?”);
”。我感觉你的插座没有连接,即使在主视图控制器内也是如此。我添加了它并得到了打印输出-我现在不完全确定我是否正确添加了插座。我通过将TableView拖动到MasterViewController.h文件中添加了它,作为IBOutlet UITableView*TableView,是这样吗?我将其更改为self.tableView,然后我没有得到打印输出,但仍然没有重新加载cellForRowIndexPath(不过节中的行数现在正在工作)。
dispatch_async(dispatch_get_main_queue(), ^{
[detailControllerTwo updateTable];
NSLog(@"%@", detailControllerTwo);
});