【发布时间】:2012-08-06 16:40:52
【问题描述】:
我有一个与UITableViewController 链接的导航视图控制器。
在表视图控制器中,我有静态单元格。我有表格视图单元格的正确标签格式。单击UITableViewCell 时,我将导航到UIViewController,然后当我导航回UITableViewController 时,我想更新UITableViewCell 上的详细信息标签。
我可以将 thenter code heree UIViewController 的值传递给 UITableViewcontroller。我已经使用NSLog 验证了这一点。但我无法更新单元格中的详细标签。
我使用了-(void) tableView:(UITableView *) tableView didDeselectRowAtIndexPath,但这对我没有帮助,因为只有当我单击另一个表格视图单元格时,表格视图单元格才会更新。我希望当我导航回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。
【问题讨论】:
-
请发布您的 cellForRowAtIndexPath,它似乎是导致问题的原因..
标签: objective-c ios ios5 uitableview