Après avoir entré avec un nouvel élément, dans la méthode délégué de UIAlertView
, j'appelle reloadData
de UITableview
et ce ne sont pas mis à jour:uitableview pas rechargeant après UIAlertView
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
// If row is deleted, remove it from the list.
if (editingStyle == UITableViewCellEditingStyleDelete)
{
if (indexPath.row > 0)
{
[datController RemoveData:indexPath.row-1];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
}
else if(editingStyle == UITableViewCellEditingStyleInsert)
{
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Enter the item." message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok",nil];
fldItem = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[fldItem setBackgroundColor:[UIColor whiteColor]];
[myAlertView addSubview:fldItem];
[tableView reloadData];
[myAlertView show];
[myAlertView release];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0){}
else
{
[datController AddData:fldItem.text];
[self.tableView reloadData];
}
}
Notez que reloadData
dans la méthode commitEditingStyle
, je mettre à des fins de débogage seulement, et cet endroit ça fonctionne.
Méthode cellForRowAtIndexPath
qui redessine la tableview, ne se déclenche pas après l'exécution reloadData
:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//Try to get rusable (rusable) cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
if (cell == nil)
{
//If not possible create a new cell
cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0,0,0,0) reuseIdentifier:@"CellIdentifier"] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Get the string to display and set the value in the cell
if(indexPath.row == 0)
{
cell.textLabel.text = @"Add items...";
}
else
{
cell.textLabel.text = [datController ListData:indexPath.row-1];
}
return cell;
}
Je ne suis pas sûr que self.tableview n'est pas nul. En fait, j'ai des doutes quant à l'appel de reloadData à partir de Tableview, dans la méthode déléguée cellForRowAtIndexPath. Une suggestion? Merci. – musicnt
Vous ne devez absolument pas appeler 'reloadData' de' cellForRowAtIndexPath'. – imaginaryboy
Désolé, je voulais dire la méthode clickedButtonAtIndex. Comment dois-je appeler dans cette méthode. – musicnt