我的UITableView有两个自定义单元格:cell1和cell2。
我的UITableView根据枚举值显示其中之一。
如果enumValue == 0,则显示cell1,表格不应允许重新排序。 如果enumValue > 0,则显示cell2,表格应允许重新排序。
所有这些都运行良好。随着枚举值的更改,重新排序控件会适当地显示。
我的问题:当重新排序控件出现在单元格上时,当行滚动出视图时,它们将消失。为什么会发生这种情况?
对于格式和粗糙的代码,我很抱歉。我遇到了网站问题。是否有任何明显的问题可能会导致这种情况?
> // enum
>
> -(void)setScorePhase:(phase)scorePhase {
>
> _scorePhase = scorePhase;
>
> if (scorePhase > score) {
> self.btnPrevious.hidden = NO;
> [self.tableCorps setEditing:YES animated:YES];
> } else {
> self.btnPrevious.hidden = YES;
> [self.tableCorps setEditing:NO animated:YES];
> }
>
> switch (scorePhase) {
> case score:
> self.lblInstructions.text = @"Give your scores";
> self.btnNext.titleLabel.text = @"Next";
> break;
> case bestdrums:
> self.lblInstructions.text = @"Order the corps by best percussion";
> self.btnNext.titleLabel.text = @"Next";
> break;
> case besthornline:
> self.lblInstructions.text = @"Order the corps by best hornline";
> self.btnNext.titleLabel.text = @"Next";
> break;
> case bestguard:
> self.lblInstructions.text = @"Order the corps by best colorguard";
> self.btnNext.titleLabel.text = @"Next";
> break;
> case loudesthornline:
> self.lblInstructions.text = @"Order the corps by loudest hornline";
> self.btnNext.titleLabel.text = @"Next";
> break;
> case favorite:
> self.lblInstructions.text = @"Order the corps by your favorite";
> self.btnNext.titleLabel.text = @"Submit";
> break;
>
> default:
> self.lblInstructions.text = @"Error";
> break;
> }
> [self.tableCorps reloadData];
}
>
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
>
> return 2;
> }
>
> -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
>
> switch (section) {
> case 0: return @"World Class";
> case 1: return @"Open Class";
> default: return @"Error";
> }
> }
>
> - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
>
> if ([self.arrayOfPerformingCorps count]) {
> switch (section) {
> case 0: return [self.arrayOfWorldClass count];
> case 1: return [self.arrayOfOpenClass count];
> default: return 0;
> }
> } else {
> return 0;
> }
> }
>
> -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
>
> UITableViewCell *cell;
> if (self.scorePhase == score) {
> cell = [self.tableCorps dequeueReusableCellWithIdentifier:@"cell1"];
>cell.showsReorderControl = NO;
>
> } else {
> cell = [self.tableCorps dequeueReusableCellWithIdentifier:@"cell2"];
>cell.showsReorderControl = YES;
>
> }
>
>
> PFObject *corps;
> if ([self.arrayOfPerformingCorps count]) {
> if ((int)[indexPath section] == 0) {
> corps = [self.arrayOfWorldClass objectAtIndex:[indexPath row]];
> } else {
> corps = [self.arrayOfOpenClass objectAtIndex:[indexPath row]];
> }
>
> UILabel *corpsNameLabel = (UILabel *)[cell viewWithTag:0];
> corpsNameLabel.text = corps[@"corpsName"];
>
>
> } else {
> //cell.textLabel.text = @"";
> //cell.detailTextLabel.text = @"";
> }
>
> return cell;
> }
>
> #pragma mark - Table Reordering
> - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
> if (self.scorePhase > score) return YES;
> else return NO;
> }
> - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
> return UITableViewCellEditingStyleNone;
> }
> - (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
> return NO;
> }
> - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
> return YES;
> }
> - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath
> toIndexPath:(NSIndexPath *)destinationIndexPath{
>
> }
>
> - (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath
> *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
> {
> if (sourceIndexPath.section != proposedDestinationIndexPath.section) {
> NSInteger row = 0;
> if (sourceIndexPath.section < proposedDestinationIndexPath.section) {
> row = [tableView numberOfRowsInSection:sourceIndexPath.section] - 1;
> }
> return [NSIndexPath indexPathForRow:row inSection:sourceIndexPath.section];
> }
>
> return proposedDestinationIndexPath;
> }