Xcode 填充表视图赢得';t显示数据

Xcode 填充表视图赢得';t显示数据,xcode,uitableview,populate,Xcode,Uitableview,Populate,我是一个新手程序员,正在学习特洛伊·布兰特的《iPad和iPhone应用程序开发全白痴指南》(我的问题在第14章“Frenemy”应用程序中)。发布时,Xcode 4.2不存在。这一事实以及这本书充斥着打字错误的事实使得这一学习经历令人沮丧,但也很有价值。唉,我遇到了一个我似乎无法解决的问题。我创建了一个表视图,并用twitter用户名填充它。我严格遵守了这本书,甚至下载了作者“完成”的源代码。在运行时,只会显示我的表视图和导航栏,但表是完全空的。当我运行他“完成”的源代码时,同样的事情发生了。

我是一个新手程序员,正在学习特洛伊·布兰特的《iPad和iPhone应用程序开发全白痴指南》(我的问题在第14章“Frenemy”应用程序中)。发布时,Xcode 4.2不存在。这一事实以及这本书充斥着打字错误的事实使得这一学习经历令人沮丧,但也很有价值。唉,我遇到了一个我似乎无法解决的问题。我创建了一个表视图,并用twitter用户名填充它。我严格遵守了这本书,甚至下载了作者“完成”的源代码。在运行时,只会显示我的表视图和导航栏,但表是完全空的。当我运行他“完成”的源代码时,同样的事情发生了。我的问题是:是否应该调用特定的方法(例如updateInterface)来显示我告诉表要收集的数据,还是应该

-(void)viewDidLoad
{
    [super viewDidLoad];

    self.title = @"Frenemies";

    frenemiesTableView.dataSource = self;
    frenemiesTableView.delegate = self;   
}
…方法够了吗?另外,如果我应该调用updateInterface relative,我该如何定义该方法?我整个星期都在使用这个网站,最后决定注册并问我的第一个问题,因为到目前为止,你们已经能够引导我找到很好的答案。我非常感谢你的建议

以下内容在我的FrenemiesViewController.m类中:

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //following line tells the table to create as many rows as rootUser has frenemies
    return [rootUser.frenemies count];
}


//give the table view the cell to display for a single row

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //REUSE CELLS FOR BEST SCROLLING PERFORMANCE
    static NSString *cellId = @"cellId";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell)
    {
        //create a cell only if one couldn't be reused
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
    }

    //DISPLAY FRENEMY'S NAME INSIDE THE CELL
    NSDictionary *frenemyDict = [rootUser.frenemies objectAtIndex:indexPath.row];
    cell.textLabel.text = [frenemyDict objectForKey:@"name"];
    return cell;
}

您没有向我们显示您的数据源。您的表需要加载某种数据

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.title = @"Frenemies";

    frenemiesTableView.dataSource = self;
    frenemiesTableView.delegate = self;  

    someArray = [NSArray arrayWithObjects:@"One",@"Two",@"Three",nil];
}
返回
someArray
中的对象数

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [someArray count];
}
someArray
加载到表中:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text = [someArray objectAtIndex:indexPath.row];

    return cell;
}

如果要重新加载UITableView的内容,请使用-reloadData方法。

问题中忘记提及。是的,我已多次检查以确保FrenemiesViewController.xib文件具有正确的连接。仍然没有骰子。数据源是什么?你有要加载的表的数组吗?也要粘贴代码。这本书实际上规定应该使用字典,因为Twitter API的原始响应是字典。这本书出版后,推特API是否有可能发生了变化,而这正是出现故障的地方?只需将实现放在原始问题中即可。这本书说它使用字典,因为推特API的原始响应是字典。有没有可能这本书出版后发生了变化,导致了问题?没有,字典应该加载到数组中。明白了!我为这本书中的章节下载的TwitterHelper.m文件有一个不完整的fetchFrenemiesForUsername方法。哇,那是一个巨大的痛苦。谢谢你试着帮我。谢谢你抽出时间。