0

IB で 3 つの異なるセルを作成しました。1 つは UIStepper を使用し、もう 1 つは Switch を使用し、もう 1 つは TextField を使用します。ステッパーの 1 つで値を設定すると、別のステッパーが自動的に同じ値を取得します。どうしてこれなの?これが私の cellForRowAtIndexPath メソッドです:

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 2) {
        UITableViewCell *cell;
        if (indexPath.row == 0 || indexPath.row == 16 || indexPath.row == 15) {
            cell = [self.tableView dequeueReusableCellWithIdentifier:@"TextFieldCell"];
            if (cell == nil)
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TextFieldCell"];
        }
        else if (indexPath.row == 17) {
            cell = [self.tableView dequeueReusableCellWithIdentifier:@"BoolCell"];
            DCRoundSwitch *roundSwitch = (DCRoundSwitch *)[cell viewWithTag:1];
            roundSwitch.onText = @"Yes";
            roundSwitch.offText = @"No";
        }
        else {
            cell = [self.tableView dequeueReusableCellWithIdentifier:@"StepperCell"];
        }
        UILabel *myLabel = (UILabel *)[cell viewWithTag:3];
        myLabel.text = [[_tableArray objectAtIndex:2] objectAtIndex:indexPath.row];
        if (cell == nil) {
            NSLog(@"cell er nil");
            return [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"StepperCell"];
        }
        return cell;
    }

私にとって問題になるのは、十分な行がある2番目のセクションだけです。UILabels は正しく表示されますが、ステッパーは何らかの形で接続されています。

4

1 に答える 1

1

既存のStepperCellsを再利用していますが、これは良いことですが、再利用するときに、そのセル内のすべてに正しい値を設定する必要があります。

于 2012-10-25T11:58:35.500 に答える