开发者

I getting exception, while deleting a row using " commitEditingStyle " method in iPhone simulator

开发者 https://www.devze.com 2022-12-28 23:14 出处:网络
I am getting exception by deleting a row from the table view. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

I am getting exception by deleting a row from the table view.

- (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 开发者_JAVA百科line at indexpath
                    [theTableView reloadData];

                }
            }
        }
        else
        {
            //adding
        }

        [theTableView reloadData];

    }

}

the exception as

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


i think you you are making mistake in providing no of Section and no of rows so check it by putting break point does it works properly or not.

0

精彩评论

暂无评论...
验证码 换一张
取 消