1

ViewWillAppearメソッドが呼び出されるたびにテーブルビューのセクションをリロードしたいので、次のように実装しました。

- (void)viewWillAppear:(BOOL)animated {

    NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:0 inSection:1];
    reloadRows = [NSArray arrayWithObjects:rowToReload, nil];
    [self.tableView reloadRowsAtIndexPaths:reloadRows withRowAnimation:UITableViewRowAnimationNone];
}

各テーブルビューセクションに表示するコンテンツを示すrowforsectionメソッドは次のとおりです。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"fadk");
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"PINGAS"];
    [self.tableView setAlwaysBounceVertical:YES];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1
                                       reuseIdentifier:@"PINGAS"] autorelease];
        cell.accessoryType = UITableViewCellAccessoryNone;


       // if ([indexPath section] == 0) {
            UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 3, 300, 41)];
            UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 0, 300, 120)];
            UIView *paddingView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 0)] autorelease];
            paddingView.backgroundColor = [UIColor cyanColor];


          //  if ([indexPath row] == 0) {
        if ([indexPath section] == 0) {
            NSLog(@"0");
            [cell addSubview:textField];
            if ([indexPath row] == 0) {
                textField.placeholder = @"Title";
            }
            else{
                textField.placeholder = @"Location";
            }
        }
        else if ([indexPath section] == 1) {
            NSLog(@"1");
            NSDateFormatter *formatter;
            NSString *eSString1;
            NSString *eEString2;
            formatter = [[NSDateFormatter alloc] init];
            [formatter setDateFormat:@"h:mm a"];

            cell.textLabel.text = @"Starts\nEnds";
            cell.textLabel.numberOfLines = 2;
            eSString1 = [formatter stringFromDate:eSTime];
            eEString2 = [formatter stringFromDate:eEtime];
            cell.detailTextLabel.text = [NSString stringWithFormat:@"%@\n%@", eSString1, eEString2];
            cell.detailTextLabel.numberOfLines = 2;
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

        }
        else{

            NSLog(@"2");
            [cell addSubview:textView];

        }

            textField.delegate = self;
            textField.leftView = paddingView;
            textField.leftViewMode = UITextFieldViewModeAlways;
            textField.adjustsFontSizeToFitWidth = YES;
            textField.textColor = [UIColor blackColor];
            textField.keyboardType = UIKeyboardTypeAlphabet;
            textField.returnKeyType = UIReturnKeyDone;  
            textField.backgroundColor = [UIColor clearColor];
            textField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
            textField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
            textField.textAlignment = UITextAlignmentLeft;
            textField.tag = 0;
            //playerTextField.delegate = self;

            textField.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right
            [textField setEnabled: YES];



            [textField release];

        textView.delegate = self;
        textView.textColor = [UIColor blackColor];
        textView.keyboardType = UIKeyboardTypeAlphabet;
        textView.returnKeyType = UIReturnKeyDone;
        textView.backgroundColor = [UIColor clearColor];
        textView.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
        textView.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
        textView.textAlignment = UITextAlignmentLeft;
        textView.tag = 0;



        [textView release];
       // }
    }
    return cell;    
}

これは最初のロードでうまく機能し、viewWillAppearを最初に呼び出した後、セクションは最初のロードと2番目のロードからのデータをリサイクルしているように見えます。 viewWIllAppearセクションで呼び出すセクション。

4

1 に答える 1

7

リロードは、更新の開始/終了の間に挟む必要があります。

[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:reloadRows withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
于 2012-04-21T16:48:23.430 に答える