[英]Core Data - Reordering TableView won't save
。
你好,
我有以下代碼來設置tableView的重新排序。
#pragma mark Row reordering
// Determine whether a given row is eligible for reordering or not.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
// Process the row move. This means updating the data model to <span id="IL_AD6" class="IL_AD">correct</span> the item indices.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath {
NSString *item = [arr objectAtIndex:fromIndexPath.row];
[arr removeObject:item];
[arr insertObject:item atIndex:toIndexPath.row];
}
但是,當我重新加載TableView時(請注意不是TableViewController),該順序被重新設置為更改任何內容之前的順序。
現在,當我為此視圖設置編輯(刪除按鈕)時,我必須添加以下行:
[self.mainTableView setEditing:YES animated:YES];
才出現在我看來。
我需要對表視圖的重新排序進行設置以保存它嗎?
從核心數據數據庫中獲取數據。
恐怕為了保持對象的順序,恐怕您需要為該數據模型 添加一個屬性 。 只需使用int
/ [NSNumber]
並在移動表視圖行時循環重新計算它們即可。
重新加載數據時,是否要使用從Core Data實體中獲取的結果重新填充該數組? 如果是這樣,您對陣列所做的更改(我認為是電視的數據源)將被吹走。 如果要保留這些更改,則需要以某種方式更新模型,以確保重新填充數組會導致按所需方式對數組進行索引。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.