小白跪求解决方案,objective c 一个出错问题,具体看问题补充

照着书模拟了个小软件,屏幕上两个按钮,一个edit 一个new 点击new可以创建新的便签,点击edit可以删除便签,也可以移动便签,但我无意间在移动完便签后点了new按钮,软件崩溃,,,但是在edit的时候再点击new按钮却可以接着添加新的标签。。。。只有移随便移动标签后不可以添加标签,求大神解决如何在移动完以后能接着点new创建标签或者最起码不创建标签但别让软件崩溃。。。
部分代码如下:

  • (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath

{

[[BNRItemStore sharedStore] moveitematindex:sourceIndexPath.row toindex:destinationIndexPath.row];

}

  • (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

if (editingStyle == UITableViewCellEditingStyleDelete) {

    NSArray *items = [[BNRItemStore sharedStore] allItems];

    BNRItem *item = items[indexPath.row];

    [[BNRItemStore sharedStore] removeitem:item];

    [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];

}

}

  • (IBAction)addnewitem:(id)sender

{

BNRItem *newitem = [[BNRItemStore sharedStore] createItem];

NSInteger lastrow = [[[BNRItemStore sharedStore] allItems] indexOfObject:newitem];

NSIndexPath *indexpath = [NSIndexPath indexPathForRow:lastrow inSection:0];

[self.tableView insertRowsAtIndexPaths:@[indexpath] withRowAnimation:UITableViewRowAnimationTop];

}

  • (IBAction)toggleeditingmode:(id)sender

{

if (self.isEditing) {

    [sender setTitle:@"edit" forState:UIControlStateNormal];

    [self setEditing:NO animated:YES];

}

else{

    [sender setTitle:@"done" forState:UIControlStateNormal];

    [self setEditing:YES animated:YES];

}

}

  • (void)moveitematindex:(NSUInteger)fromindex toindex:(NSUInteger)toindex

{

if (fromindex == toindex) {

    return;

}

BNRItem *item = self.privateItems[fromindex];

[self.privateItems insertObject:item atIndex:toindex];

}

  • (void) removeitem:(BNRItem *)item

{

[self.privateItems removeObjectIdenticalTo:item];

}

  • (instancetype)initPrivate

{

self = [super init];

if (self) {

    _privateItems = [[NSMutableArray alloc] init];

}

return self;

}

  • (NSArray *)allItems

{

return [self.privateItems copy];

}

  • (BNRItem *)createItem

{

BNRItem *item = [BNRItem randomItem];

[self.privateItems addObject:item];

return item;

}
出错的地方到底在哪啊。。。。必要的话整个软件我可以传到网盘上!!!