3

我正在为 iOS 6 的数据管理系统开发应用程序。这是我的代码:

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    self.navigationItem.title = @"Detail";

    if (self.student.thumbnailImage != nil) {
        [self.imageButton setImage:[UIImage imageWithData:self.student.thumbnailImage] forState:UIControlStateNormal];
    } else {
        [self.imageButton setImage:[UIImage imageNamed:@"Default_photo3.png"] forState:UIControlStateNormal];

    }

    NSLog(@"Student First = %@", self.student.firstname);
    self.firstNameTF.text = self.student.firstname;

    NSLog(@"Student Last = %@", self.student.lastname);
    self.lastNameTF.text = self.student.lastname;

    NSLog(@"Student IC = %@", self.student.ic);
    self.icTF.text = self.student.ic;

    NSLog(@"Student Form = %@", self.student.form);
    self.formTF.text = self.student.form;

    NSLog(@"Student Gender = %@", self.student.gender);
    self.genderTF.text = self.student.gender;

    NSLog(@"Student Birthday = %@", self.student.birthday);

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd/MM/yyyy"];
    NSString *date = [dateFormatter stringFromDate:self.student.birthday];
    self.birthdateTF.text = date;;
    self.dateButton.titleLabel.text =date;



    NSLog(@"Address = %@", self.student.address.street);
    NSLog(@"Zip = %@", self.student.address.zip);
    NSLog(@"City = %@", self.student.address.city);
    NSLog(@"State = %@", self.student.address.state);

    [self updateImageButton];

    //Create a mutable array for guardians
    NSSortDescriptor *sortDEscriptors = [[NSSortDescriptor alloc]initWithKey:@"firstname" ascending:YES];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDEscriptors, nil];

    NSMutableArray *sortedGuardians = [[NSMutableArray alloc] initWithArray:[self.student.guardians allObjects]];

    [sortedGuardians sortUsingDescriptors:sortDescriptors];

    self.guardiansArray= sortedGuardians;

    [self.tableView reloadData];
}

我发现我的表格视图一开始没有滚动。但是当我删除[self.tableView reloadData]这部分中的时,它确实滚动正常。有谁知道为什么?我需要把它放在[self.tableView reloadData]这里,以便在编辑后更新数据。

4

2 回答 2

0

将 reloadData 放在 ViewDidAppear 方法中,这样您将在视图出现之前设置数据并在视图出现后请求重新加载。

于 2013-03-05T11:19:17.710 回答
0

您可以像重新加载数据之前一样设置偏移量

CGPoint offset = self.tableView.contentOffset;
[self.tableView reloadData];
[self.view layoutIfNeeded];
[self.tableView setContentOffset:offset animated:NO];

希望这会对某人有所帮助

于 2018-07-11T14:01:52.560 回答