reloadData不起作用 [英] reloadData doesn't work

查看:242
本文介绍了reloadData不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更新我的UITableview但是当我调用 [tableView reloadData]; 该表不会更新,在我滚动tableview上面的名称之后细胞同时被改变。但它并没有添加新行或类似的东西。

i'm trying to update my UITableview but when i call [tableView reloadData]; the table doens't update, after i scroll the tableview above the name of the cell while be changed. But it's not adding a new row or something like that.

-(void)update {
        [tableView reloadData];

    NSLog(@" %i", [tableData count]);
}

当我添加一行它返回2但是表时,它正在退回1的nslog没有更新。

The nslog it's returing 1 when i add a row it's returning 2 but the table is not updating.

- (void) refresh:(id)sender {  


    NSString *jsonString = [NSString 
                            stringWithContentsOfURL:[NSURL URLWithString:xmlDataUrl] 
                            encoding:NSUTF8StringEncoding
                            error:nil];


    SBJSON *parser = [[SBJSON alloc] init];
    NSDictionary *results = [parser objectWithString:jsonString error:nil];

    parser = nil;

    [self setTableData:[results objectForKey:@"items"]];
        [self performSelector:@selector(update) withObject:nil afterDelay:.2];


}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        // Change UITableViewCellStyle
        cell = [[UITableViewCell alloc] 
                initWithStyle:UITableViewCellStyleSubtitle 
                reuseIdentifier:CellIdentifier];
    }


    NSDictionary *item = [tableData objectAtIndex:[indexPath row]];
    [[cell textLabel] setText:[item objectForKey:@"title"]];
    [[cell detailTextLabel] setText:[item objectForKey:@"descript"]];
    [[cell detailTextLabel] setText:[item objectForKey:@"detail"]];

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

        return [tableData count];
}


推荐答案

我每次见过这个问题是因为没有连接 UITableView 插座。因此, reloadData 调用将发送到 nil 。这几乎可以肯定是这种情况下的错误。这可以通过简单的日志语句轻松测试。

Every-time I have seen this problem it is a result of the UITableView outlet not being connected. As a result the reloadData call is sent to nil. This is almost certainly what is wrong in this case. This can be easily tested by a simple log statement.

-(void)update {
    NSLog(@"tableView is '%@'",tableView);
    [tableView reloadData];
    NSLog(@" %i", [tableData count]);
}

你很可能会看到 tableView是(在控制台中

More likely than not you will see tableView is (null) in the console.

旁注
tableview完全填充的事实表示已连接 dataSource 委托个网点。

这篇关于reloadData不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆