ReloadData not working

I am trying to update my UITableview, but when I call [tableView reloadData];, the table update is not updated after I scroll the table view over the cell name when changing. But this is not adding a new line or anything like that.

-(void)update {
        [tableView reloadData];

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

In nslog it is saved 1 when I add a row returning 2, but the table is not updated.

- (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];
}
+3
source share
1 answer

Every time I saw this problem, this is the result of no way out UITableView. As a result, the call is reloadDatasent to nil. In this case, it is almost certain. This can be easily verified with a simple log statement.

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

Most likely, you will see tableView is (null)in the console.

: , , , dataSource delegate .

+5

All Articles