ReloadData不刷新Tableview

时间:2011-03-19 12:58:38

标签: iphone ios4

我正在使用UIViewController,其中包含表视图控件。

在ViewDidLoad事件中,我初始化tableview,这是代码

listView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStyleGrouped];
listView.delegate = self;
listView.dataSource = self;
listView.autoresizesSubviews = YES;

然后我调用webservice来填充NSMutableArray。在connectionDidFinishLoading事件中,我将NSmutableArray复制到数据源。

XMLParser *parser = [[XMLParser alloc] initXMLParser];
[xmlParser setDelegate:parser];

BOOL success = [xmlParser parse];

if(success)
{
    listData = [parser.localTaskList copy];
    [listView reloadData];          
}
else 
{
    NSLog (@"Error parsing Facilities");        
}

这是tableview事件中的代码。

(NSInteger)tableView:(UITableView *)tableView
        numberOfRowsInSection:(NSInteger)section
{
    return [listData count];    
}

IndexPath事件中的行的单元格。

(UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *EditCellIdentifier = @" editcell";


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:EditCellIdentifier];
    if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:EditCellIdentifier] autorelease];
    //}
        if ([listData count] > 0) {

            UILabel *label = [[UILabel alloc] initWithFrame:kLabelRect];
            label.tag = kCellLabelTag;
            label.text=[[listData objectAtIndex:indexPath.row] TaskID];
            [cell.contentView addSubview:label];
            [label release];

            UIImageView *imageView = [[UIImageView alloc] initWithImage:unselectedImage];
            imageView.frame = CGRectMake(5.0, 10.0, 23.0, 23.0);
            [cell.contentView addSubview:imageView];
            imageView.hidden = !inPseudoEditMode;
            imageView.tag = kCellImageViewTag;
            [imageView release];
        }   
    }



    [UIView beginAnimations:@"cell shift" context:nil];

    UILabel *label = (UILabel *)[cell.contentView viewWithTag:kCellLabelTag];
    //label.text = [listData objectAtIndex:[indexPath row]];
    label.frame = (inPseudoEditMode) ? kLabelIndentedRect : kLabelRect;

    UIImageView *imageView = (UIImageView *)[cell.contentView viewWithTag:kCellImageViewTag];
    NSNumber *selected = [selectedArray objectAtIndex:[indexPath row]];
    imageView.image = ([selected boolValue]) ? selectedImage : unselectedImage;
    imageView.hidden = !inPseudoEditMode;
    [UIView commitAnimations];

    // set the default detail button
    if (inPseudoEditMode) {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    else {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    return cell;

}

节数事件

(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return 1;   
}

但是reloadData不会刷新UITableview。

2 个答案:

答案 0 :(得分:1)

如果你移动这条线,我认为你会找到更好的成功:

label.text=[[listData objectAtIndex:indexPath.row] TaskID];

从单元格创建块内部到该块之后的点。我注意到你在阻止之后有一条类似的线,但它被注释掉了。单元格的所有每行设置应在单元格创建块之后进行。

答案 1 :(得分:0)

您可能希望在cellForRowAtIndexPath函数中放置断点。我想您会注意到在调用reloadData之后调用了函数,但是因为您有静态单元标识符 - 所以没有任何单元格被重新创建。

有很多方法可以解决这个问题。如果我是对的,请告诉我。

相关问题