ultragtx / GSBookShelf

An iBooks-styled book shelf for iOS (Animation of drag & drop, insert, remove...)
Other
426 stars 90 forks source link

Book Index #3

Closed pixelbitapps closed 12 years ago

pixelbitapps commented 12 years ago

There is currently an issue whereby when you move books to new indexes, the book index will stay the same as it previously was. Also, when you create a new book, it will set the new book's index to '0', but the old book at '0' will also be at index '0' so there will be two 0 indexes.

Anybody with any answers as to why this may be happening can email me at james@pixelbitapps.com - I would greatly appreciate it. Thanks!

ultragtx commented 12 years ago

@pixelbitapps The index of the book is set by YOU, the control just tell you a book has been moved from one index to another (by calling the delegate method) When you add books, it's the same, YOU reset the index and tell the control to add books.

All the data was managed by you the control just show the data. And the control will alert you when and how you should make some change to your data.

pixelbitapps commented 12 years ago

I know but I have the following when adding a new book and it will produce a very strange range of indexes (explained above):

[_bookArray insertObject:[NSNumber numberWithInt:0] atIndex:0]; [_bookStatus insertObject:[NSNumber numberWithInt:BOOK_UNSELECTED] atIndex:0]; NSIndexSet *set = [NSIndexSet indexSetWithIndex:0]; [_bookShelfView insertBookViewsAtIndexs:set animate:YES];

Is this what it should be?

ultragtx commented 12 years ago

@pixelbitapps in [_bookArray insertObject:[NSNumber numberWithInt:0] atIndex:0]; You insert an [NSNumber numberWithInt:0], and the number here means this bookView's image is 0.png not the index.

And yeah, it's my fault. I should fix the initBooks like this

- (void)initBooks {
    NSInteger numberOfBooks = 100;
    _bookArray = [[NSMutableArray alloc] initWithCapacity:numberOfBooks];
    _bookStatus = [[NSMutableArray alloc] initWithCapacity:numberOfBooks];
    for (int i = 0; i < numberOfBooks; i++) {
        NSNumber *number = [NSNumber numberWithInt:i % 4 + 1];
        [_bookArray addObject:number]; // the image number not index
        [_bookStatus addObject:[NSNumber numberWithInt:BOOK_UNSELECTED]];
    }

    _booksIndexsToBeRemoved = [NSMutableIndexSet indexSet];
}

And you can see in the method below I insert several "1" to _booksArray

- (void)addButtonClicked:(id)sender {
    int a[6] = {1, 2, 5, 7, 9, 22};
    NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
    NSMutableArray *arr = [NSMutableArray array];
    NSMutableArray *stat = [NSMutableArray array];
    for (int i = 0; i < 6; i++) {
        [indexSet addIndex:a[i]];
        [arr addObject:[NSNumber numberWithInt:1]];
        [stat addObject:[NSNumber numberWithInt:BOOK_UNSELECTED]];
    }
    [_bookArray insertObjects:arr atIndexes:indexSet];
    [_bookStatus insertObjects:stat atIndexes:indexSet];
    [_bookShelfView insertBookViewsAtIndexs:indexSet animate:YES];
}