Hi
after entering with a new item, in the delegate method from UIAlertview, I calling reloadData from Tableview and it is not being updated:
- (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];
}
}
Note that reloadData in the method commitEditingStyle, I put in for debugging purposes only, and this place it's working.
Method cellForRowAtIndexPath which redraws the tableview, is not fired after execute 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;
}
Thanks
Smith