照着书模拟了个小软件,屏幕上两个按钮,一个edit 一个new 点击new可以创建新的便签,点击edit可以删除便签,也可以移动便签,但我无意间在移动完便签后点了new按钮,软件崩溃,,,但是在edit的时候再点击new按钮却可以接着添加新的标签。。。。只有移随便移动标签后不可以添加标签,求大神解决如何在移动完以后能接着点new创建标签或者最起码不创建标签但别让软件崩溃。。。
部分代码如下:
{
[[BNRItemStore sharedStore] moveitematindex:sourceIndexPath.row toindex:destinationIndexPath.row];
}
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSArray *items = [[BNRItemStore sharedStore] allItems];
BNRItem *item = items[indexPath.row];
[[BNRItemStore sharedStore] removeitem:item];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
{
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];
}
{
if (self.isEditing) {
[sender setTitle:@"edit" forState:UIControlStateNormal];
[self setEditing:NO animated:YES];
}
else{
[sender setTitle:@"done" forState:UIControlStateNormal];
[self setEditing:YES animated:YES];
}
}
{
if (fromindex == toindex) {
return;
}
BNRItem *item = self.privateItems[fromindex];
[self.privateItems insertObject:item atIndex:toindex];
}
{
[self.privateItems removeObjectIdenticalTo:item];
}
{
self = [super init];
if (self) {
_privateItems = [[NSMutableArray alloc] init];
}
return self;
}
{
return [self.privateItems copy];
}
{
BNRItem *item = [BNRItem randomItem];
[self.privateItems addObject:item];
return item;
}
出错的地方到底在哪啊。。。。必要的话整个软件我可以传到网盘上!!!