我在使用UIViewController的地方有表格視圖控件。重新加載數據不會刷新表格視圖
在viewDidLoad中事件中,我初始化的tableview,這裏是代碼
listView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStyleGrouped];
listView.delegate = self;
listView.dataSource = self;
listView.autoresizesSubviews = YES;
然後調用web服務來填充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。
我嘗試了cellForRowAtIndexPath函數中的斷點。在reloaddata方法調用後,它甚至不會觸發該函數。 – user667304 2011-03-20 10:56:45