Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我在iPhone模拟器中使用“CommittedItingStyle”方法删除一行时遇到异常_Iphone_Cocoa Touch - Fatal编程技术网

我在iPhone模拟器中使用“CommittedItingStyle”方法删除一行时遇到异常

我在iPhone模拟器中使用“CommittedItingStyle”方法删除一行时遇到异常,iphone,cocoa-touch,Iphone,Cocoa Touch,通过从表视图中删除一行,我得到了异常 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { if(isEdit == YES) { if([editObject.contactList count]>0) { return [editObject.contactList count]+1; } else

通过从表视图中删除一行,我得到了异常

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if(isEdit == YES)
    {
        if([editObject.contactList count]>0)
        {
             return [editObject.contactList count]+1;
        }
        else
        {
            return 1;
        }

    }   
    else if(isEdit == NO)
    {
        if([addContactList count]>0)
        {
           return [addContactList count]+1;
        }
        else
        {
            return 1;
        }
     }


    return 0;
}
- (NSInteger)tableView:(UITableView *)tableView  numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
  if(isEdit == YES)
  {
      int sectionNum=[editObject.contactList count]-1;
      if([editObject.contactList count]>0)
      {


          for( int i=0; i<=[editObject.contactList count]-1;i++)
          {
              if(indexPath.section == i)
              {

                  return UITableViewCellEditingStyleDelete;
              }
          }
          if(indexPath.section == sectionNum+1)
          {
              return UITableViewCellEditingStyleInsert;
          }

      }     
      else
      {
          if(indexPath.section == 0)
          {
              return UITableViewCellEditingStyleInsert;
          }
      }


  }
  else
  {
      if([addContactList count]>0)
      {
          int sectionNum=[addContactList count]-1;

          for( int i=0; i<=[addContactList count]-1;i++)
          {
              if(indexPath.section == i)
              {
                  return UITableViewCellEditingStyleDelete;
              }
          }
          if(indexPath.section == sectionNum+1)
          {
              return UITableViewCellEditingStyleInsert;
          }
      }     
      else
      {
          if(indexPath.section == 0)
          {
              return UITableViewCellEditingStyleInsert;
          }
      }
  }
  return UITableViewCellEditingStyleNone;
}
- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if(isEdit == YES)
    {
        if(editingStyle == UITableViewCellEditingStyleDelete)
        {
            for(int i=0;i<=[editObject.contactList count]-1;i++)
            {
                if(indexPath.section == i)
                {
                    [editObject.contactList removeObjectAtIndex:indexPath.row];
                    [theTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
                                        withRowAnimation:UITableViewRowAnimationFade];
                }
            }
        }
        else
        {
            //adding
        }
        [theTableView reloadData];
    }
    else
    { 
        if(editingStyle == UITableViewCellEditingStyleDelete)
        {
            for(int i=0;i<=[addContactList count]-1;i++)
            {
                if(indexPath.section == i)
                {
                [addContactList removeObjectAtIndex:indexPath.row];
       [theTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] 
                            withRowAnimation:UITableViewRowAnimationFade];    // getting exception here in this line at indexpath
                    [theTableView reloadData];

                }
            }
        }
        else
        {
            //adding
        }

        [theTableView reloadData];

    }

}

我认为您在提供节数和行数方面犯了错误,因此请通过设置断点来检查它是否正常工作。

请格式化您的文章。这几乎是不可读的。
2010-04-28 13:55:30.063 Zoho[2818:20b] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-984.38/UITableView.m:772
2010-04-28 13:55:30.064 Zoho[2818:20b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections.  The number of sections contained in the table view after the update (2) must be equal to the number of sections contained in the table view before the update (3), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).'
2010-04-28 13:55:30.065 Zoho[2818:20b] Stack: (
    10490971,
    2437656123,
    10574907