我有一个导航 View Controller ,它与 UITableViewController
链接。 .
在表格 View Controller 中,我有静态单元格。我有表格 View 单元格的正确标签格式。我将导航到 UIViewController
当点击 UITableViewCell
然后当我导航回我的 UITableViewController
,我想更新我的 UITableViewCell
上的详细信息标签.
我能够从 enter code here
传递值e UIViewController
到UITableViewcontroller
.我已经使用 NSLog
验证了这一点.但我无法更新单元格中的详细信息标签。
我用了-(void) tableView:(UITableView *) tableView didDeselectRowAtIndexPath
但这对我没有帮助,因为只有当我单击另一个表格 View 单元格时,表格 View 单元格才会更新。我希望此更新在我导航回 UITableViewController
时自动发生
请检查以下链接
http://www.icodeblog.com/wp-content/uploads/2011/10/navigation_interface.jpeg
我想要类似上图的东西
如何才能做到这一点。
更新代码
@interface designTableViewController ()
@end
@implementation designTableViewController
{
glimmpseliteAppDelegate *appDelegate;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
appDelegate = [[UIApplication sharedApplication]delegate];
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
-(void)viewWillAppear:(BOOL)animated
{
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 8;
}
#pragma mark - Table view delegate
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == 1)
{
UITableViewCell *tb = [tableView cellForRowAtIndexPath:indexPath];
UIViewController *uiViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"designSolvingForViewController"];
[self.navigationController pushViewController:uiViewController animated:YES];
tb.detailTextLabel.text = appDelegate.solvingFor;
}
if(indexPath.row == 2)
{
UIViewController *uiViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"designTypeIErrorRate"];
[self.navigationController pushViewController:uiViewController animated:YES];
UITableViewCell *tb = [tableView cellForRowAtIndexPath:indexPath];
tb.detailTextLabel.text = appDelegate.typeIError;
}
if(indexPath.row == 3)
{
UIViewController *uiViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"designNumberOfGroups"];
[self.navigationController pushViewController:uiViewController animated:YES];
UITableViewCell *tb = [tableView cellForRowAtIndexPath:indexPath];
tb.detailTextLabel.text = appDelegate.numberOfGroups;
}
if(indexPath.row == 4)
{
UIViewController *uiViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"designRelativeGroupSize"];
[self.navigationController pushViewController:uiViewController animated:YES];
UITableViewCell *tb = [tableView cellForRowAtIndexPath:indexPath];
tb.detailTextLabel.text = appDelegate.relativeGroupSize;
}
if(indexPath.row == 5)
{
UIViewController *uiViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"designSmallestGroupSize"];
[self.navigationController pushViewController:uiViewController animated:YES];
UITableViewCell *tb = [tableView cellForRowAtIndexPath:indexPath];
tb.detailTextLabel.text = appDelegate.smallestGroupSize;
}
if(indexPath.row == 6)
{
UIViewController *uiViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"designMeansAndVariance"];
[self.navigationController pushViewController:uiViewController animated:YES];
UITableViewCell *tb = [tableView cellForRowAtIndexPath:indexPath];
tb.detailTextLabel.text = appDelegate.meansAndVariance;
}
}
- (void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == 1)
{
UITableViewCell *tb = [tableView cellForRowAtIndexPath:indexPath];
tb.detailTextLabel.text = appDelegate.solvingFor;
}
if(indexPath.row == 2)
{
UITableViewCell *tb = [tableView cellForRowAtIndexPath:indexPath];
//tb.textLabel.text =@"Sample";
tb.detailTextLabel.text = appDelegate.typeIError;
}
if(indexPath.row == 3)
{
UITableViewCell *tb = [tableView cellForRowAtIndexPath:indexPath];
//tb.textLabel.text =@"Sample";
tb.detailTextLabel.text = appDelegate.numberOfGroups;
}
if(indexPath.row == 4)
{
UITableViewCell *tb = [tableView cellForRowAtIndexPath:indexPath];
//tb.textLabel.text =@"Sample";
tb.detailTextLabel.text = appDelegate.relativeGroupSize;
}
if(indexPath.row == 5)
{
UITableViewCell *tb = [tableView cellForRowAtIndexPath:indexPath];
//tb.textLabel.text =@"Sample";
tb.detailTextLabel.text = appDelegate.smallestGroupSize;
}
if(indexPath.row == 6)
{
UITableViewCell *tb = [tableView cellForRowAtIndexPath:indexPath];
//tb.textLabel.text =@"Sample";
tb.detailTextLabel.text = appDelegate.meansAndVariance;
}
}
@end
第一个表格单元格只是一个有按钮的单元格。我有一个用于那个按钮的推送 UIViewController。
最佳答案
在 viewWillAppear 中:使用 [tableView reloadData]。
- (void)viewWillAppear:(BOOL)animated
{
[tableView reloadData];
}
关于objective-c - 从 UIViewController 导航返回时无法更新 UITableViewController 中的 TableCelView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11832425/