Я использую UIViewController, где он содержит элемент управления табличным представлением.
В событии ViewDidLoad я инициализирую табличное представление, вот код
listView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStyleGrouped];
listView.delegate = self;
listView.dataSource = self;
listView.autoresizesSubviews = YES;
, затем я вызываювеб-сервис для заполнения 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");
}
Здесь код в событиях просмотра таблицы.
(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;
}
Событие Number of Sections
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
Но reloadData не обновляет UITableview.