我在更新视图中的详细信息时遇到了一个小问题。如何在成功更新后重新加载视图以更改详细信息。
以下是我的代码。请帮我找出解决方案。在此先感谢。
- (void)viewDidLoad
{
[super viewDidLoad];
}
-(void)viewWillAppear:(BOOL)animated
{
[self viewDidLoad];
[super viewWillAppear:animated];
[self.view setNeedsDisplay];
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
profilearray=[[NSMutableArray alloc]initWithObjects:@"First Name:",@"Last Name:",@"Date of Birth:",@"Email:",@"Gender:",@"Address:",@"Country:",@"State:",@"City:",@"ZipCode:",@"Phone:",@"Guardian / Caretaker Details:",@"Name:",@"Relationship:",@"Email:",@"Doctor Details:",@"Name:",@"Phone:",@"Email:",@"Insurance Details:",@"Name:",@"Email:",nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [profilearray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [profilearray objectAtIndex:indexPath.row];
if(indexPath.row==0)
{
cell.detailTextLabel.text=[[NSUserDefaults standardUserDefaults] stringForKey:@"FirstName"];
}
if(indexPath.row==1)
{
cell.detailTextLabel.text=[[NSUserDefaults standardUserDefaults] stringForKey:@"LastName"];
}
if(indexPath.row==2)
{
cell.detailTextLabel.text=[[NSUserDefaults standardUserDefaults] stringForKey:@"DOB"];
}
if(indexPath.row==3)
{
cell.detailTextLabel.text=[[NSUserDefaults standardUserDefaults] stringForKey:@"Email"];
}
if(indexPath.row==4)
{
cell.detailTextLabel.text=[[NSUserDefaults standardUserDefaults] stringForKey:@"Gender"];
}
if(indexPath.row==5)
{
cell.detailTextLabel.text=[[NSUserDefaults standardUserDefaults] stringForKey:@"Address"];
}
return cell;
}
答案 0 :(得分:0)
使用[tableView reloadData]更新tableview
答案 1 :(得分:0)
简单使用此功能不需要查看刷新或重新加载
circle
答案 2 :(得分:0)
每次出现视图时,您的数据源数组profilearray
都会重新分配相同的值。也许在viewDidLoad
中初始化一次。
更新数组后,使用[tableView reloadData]
重新加载表视图。
请勿自行致电viewDidLoad
,暂时取消setNeedsDisplay
。
答案 3 :(得分:0)
请使用此功能。
- (void)viewDidLoad
{
[super viewDidLoad];
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
profilearray=[[NSMutableArray alloc]initWithObjects:@"First Name:",@"Last Name:",@"Date of Birth:",@"Email:",@"Gender:",@"Address:",@"Country:",@"State:",@"City:",@"ZipCode:",@"Phone:",@"Guardian / Caretaker Details:",@"Name:",@"Relationship:",@"Email:",@"Doctor Details:",@"Name:",@"Phone:",@"Email:",@"Insurance Details:",@"Name:",@"Email:",nil];
[tableView reloadData];
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
答案 4 :(得分:0)
所以在这种情况下永远不会调用viewWillAper因为这不是标准的方法 找到数据更新的点,然后调用" reloadData" For more about viewWillApear hit 感谢