我敢肯定,有一種更簡單的方法可以做到這一點,我在所有的閱讀中都缺少這一點......但這讓我瘋狂。我非常疲倦 - 如果這變得冗長,請道歉。NSFetchedResultsChangeMove在自定義UITableViewCell中顯示不正確的標籤
我在我的應用程序中使用NSFetchedResultsController - 非常標準的問題 - 它的工作原理。兩個部分,正確排序等。當用戶點擊第一部分中的單元格(創建兩個部分的屬性的BOOL值反轉)時,它將移動到第二部分(BOOL值再次翻轉) - 反之亦然。重要的,着名的作品。
這裏是我的實現有點時髦的地方。最終我想支持iAds - 根據HIG,這些應該放置在屏幕的底部......我發現要做到這一點的最簡單方法是將UITableView放入UIView中,以避免一些邏輯上的原因使我現在逃脫 - 但這就是我所擁有的 - 具有UITableView的UIView。
我正在使用原型單元格的故事板 - 兩個具體。一個用於添加內容並充當兩部分之間的分隔符。另一個是要顯示的默認單元格。當我爲這個單元格註冊IBOutlets時 - 它會拋出一個異常(這是一個問題,但我可以解決它)。所以,相反,我一直在使用cell.contentView.subviews去的元素做我需要惹:
NSArray *cellSubViews = cell.contentView.subviews;
if ([cellSubViews count] == 3) {
// editing accessory view
cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
// default background image view
cell.backgroundView = self.defaultClockCellBackgroundImageView;
// clock name label
UILabel *clockNameLabel = [cellSubViews objectAtIndex:2];
clockNameLabel.text = clock.name;
clockNameLabel.textColor = (indexPath.section == 0 && ![clock.isAddClockCell boolValue])
? [UIColor whiteColor]
: [UIColor lightTextColor];
// view child button
UIButton *viewChildButton = [cellSubViews objectAtIndex:0];
UIImage *viewChildClocksButtonBackgroundImage;
if (self.clockForFetch != nil) {
//NSLog(@"child clocks list - N/A");
viewChildClocksButtonBackgroundImage = [UIImage imageNamed:@"childcell_blank"];
viewChildButton.enabled = NO;
} else if ([clock.childClocks count] < 2) {
//NSLog(@"add child button");
viewChildClocksButtonBackgroundImage = [UIImage imageNamed:@"parentcell_addchild"];
} else if (![clock.isRunning boolValue]
|| [self totalChildClocksRunning:clock] < 1) {
//NSLog(@"view child button");
// children clocks cannot be running while parent is stopped;
// therefore, no need to actually check
// this solves the "wait for cell animation to end" issue
// without the need for tableview reload data
viewChildClocksButtonBackgroundImage = [UIImage imageNamed:@"parentcell_viewchild"];
} else {
//NSLog(@"view child running button");
viewChildClocksButtonBackgroundImage = [UIImage imageNamed:@"parentcell_viewchild_running"];
}
[viewChildButton setImage:viewChildClocksButtonBackgroundImage forState:UIControlStateNormal];
viewChildButton.hidden = NO;
// view time entries list for clock
UIButton *detailDisclosureButton = [cellSubViews objectAtIndex:1];
UIImage *detailDisclosureButtonBackgroundImage = (self.clockForFetch == nil)
? [UIImage imageNamed:@"parentcell_detaildisclosure"]
: [UIImage imageNamed:@"childcell_detaildisclosure"];
[detailDisclosureButton setImage:detailDisclosureButtonBackgroundImage
forState:UIControlStateNormal];
detailDisclosureButton.hidden = NO;
if (self.editing) {
viewChildButton.hidden = YES;
detailDisclosureButton.hidden = YES;
}
}
請注意:此方法之前我使用的是單獨的NIB與IBOutlets並可以複製這個問題 - 只是不一致。
這裏有三個單元格,當點擊時移動(Alpha,Beta和Gamma)......沒有圖像給新的抱歉 - 希望他們可以告訴我,在我上傳圖像之前 - 輸入ASCII藝術:
---------------
| alpha |
---------------
| beta |
---------------
| gamma |
---------------
| *delimiter* |
---------------
這裏是攻絲α和β細胞後的表:
---------------
| gamma |
---------------
| *delimiter* |
---------------
| beta |
---------------
| beta |
---------------
但是,如果我在標有「貝塔」第一單元上的自定義詳細公開按鈕點擊(應該讀Alpha),我得到傳遞給詳細視圖的正確對象:
--------------------------------------------
| < back detail view for alpha edit |
--------------------------------------------
因此,獲取的結果控制器正在更新 - 當它與表視圖進行對話時,它似乎並不一致地配置事物。在上面的配置單元方法中,我查看了控制器中找到的對象的名稱 - 它們也是正確的;即第一個β單元格(索引路徑爲1,0的行的單元格)是Alpha - 而不是Beta - 即使表格視圖顯示Beta。
我一直看到需要setNeedsDisplay和/或setNeedsLayout的自定義單元格的提及,但我不認爲我完全理解這一點 - 儘管我曾嘗試將它放在代碼中的任何位置。 「NSFetchedResultsChangeMove」是用戶點擊單元格時調用的 - 我嘗試了很多我在網絡上看到的變體(包括這裏)來修復我認爲相似的故障 - 無濟於事。我確定這個構造會隨着時間而成熟(因爲這是第一次去),但正如我所說的,我遇到了一個完全不同的構造(當時不存在故事板)的相同問題 - 並且仍然可以重複這個問題。
任何援助將不勝感激。而且,如果對於這個完全相同的問題在這裏有答案,我爲重複做了道歉。
Ps。來自iTunes U的Standford類有一個名爲Fetched Results Controller Table View Controller的東西......有一些關於從管理對象上下文中暫停自動更新的方法。我想知道這是否可能與問題有關;但是,並不真正知道如何檢查...仍然不熟悉Objective-C中的對象繼承。 – 2012-03-31 15:04:14