我正在为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];
}
我发现我的tableview在开头没有滚动。但是,当我删除此部分中的[self.tableView reloadData]
时,它确实正常滚动。有谁知道为什么?我需要将[self.tableView reloadData]
放在这里,以便在编辑后更新数据。
答案 0 :(得分:0)
将reloadData放在ViewDidAppear方法中,这样您就可以在视图出现之前设置数据,并在显示后请求重新加载。
答案 1 :(得分:0)
您可以设置数据重新加载之前的偏移量
CGPoint offset = self.tableView.contentOffset;
[self.tableView reloadData];
[self.view layoutIfNeeded];
[self.tableView setContentOffset:offset animated:NO];
希望这会对某人有所帮助