输入新项目后,在UIAlertView
的委托方法中,我致电reloadData
UITableview
并且未更新:
- (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];
}
}
请注意方法reloadData
中的commitEditingStyle
,我只是为了调试目的,而且这个位置正在运行。
重新绘制tableview的方法cellForRowAtIndexPath
在执行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;
}
答案 0 :(得分:0)
不确定最终会遇到什么问题,但你确定self.view
不是零吗?
在reloadData
调用正在运行的位置,您使用的是传递给您的tableView
引用,而不是self.view
,但是无效的调用正在使用{{1 }}。只有上面的代码,这是我到目前为止唯一明显的事情。