2014-03-24 73 views
-1

我有一個自定義的tableViewCell,它在故事板中的原型單元格中定義了一些子視圖。在故事板中,我將附件設置爲Disclosure Indicator,但是當滾動時(當單元格被重用時)指示器消失。UITableViewCell披露指示器在滾動中消失

我試圖將其設置在代碼:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    ... 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

它沒有正常工作。但是,我發現了一個解決方案的工作,一個非常奇怪的解決方案:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    ... 
    cell.accessoryType = UITableViewCellAccessoryNone; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

我不知道爲什麼這樣聰明能幹,但它爲我工作。任何人都可以告訴我爲什麼或者如果有其他問題/修復?

UPDATE:

我如何獲得可重複使用的電池:

ActivityWeekCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 

我也試過:

ActivityWeekCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 

if (cell == nil) { 
    cell = [[ActivityWeekCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

} 
+1

燦你sh你重複使用細胞的部分在哪裏? – streem

+0

你有沒有嘗試過使用另一個標識符?你想爲每個細胞披露指標嗎? – streem

+0

是的,我想爲每個細胞。 – simonnickel

回答

0

嘗試使用此變種:

ActivityWeekCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 

if (cell == nil) { 
    cell = [[ActivityWeekCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; 
} 
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;