我在UINavigationController中使用了具有UITableView的storyboard。 在這個UITableView中,使用了具有內部屬性的自定義tableViewCell。segue不能與UITableViewCell alloc一起工作,但dequeueReusableCellWithIdentifier
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CustomTableViewCell *cell = nil;
if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {
//iOS 6.0 below
cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
}
else {
//iOS 6.0 above
cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; //work segue
}
上面的代碼適用於push segue。但不是當我用
cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; //not work segue
我用這種alloc方法保留單元格的數據重用單元格。
這只是分配vs deque ..方法的區別。我錯過了什麼?
編輯)我知道不使用dequeReusableCell方法對性能原因不利。但是,細胞的數量不會很多。這就是爲什麼我不需要deque方法。
「不工作」的意思是「不要執行推繼續」,而不是崩潰。
它顯示的單元格與使用dequeReusable方法時相同,但單元格右側的揭示指示器圖標除外。指示器圖標來自故事板設置。
當我觸摸單元格時,單元格突出顯示爲藍色,但不推動push segue。
CustomTableViewCell有4個屬性。這與UITableViewCell完全不同。用戶在DetailViewController中設置屬性(推動segue引領這一點)。該單元格沒有IBOutlet參考。在MasterViewController(具有tableView)中,cellForRowAtIndexPath方法返回上面的CustomTableViewCell代碼。
cellForRowAtIndexPath方法在CustomTableViewCell上的指標左邊添加一個開/關按鈕 併爲該單元設置一個標籤號。
請注意,當使用Storyboard時,'dequeueReusableCellWithIdentifier'總會給你一個單元格。 – Ric 2013-02-22 23:35:55