У меня есть приложение UITableView на основе навигации.Вот как работает мое приложение.
На rootViewController у меня есть набор вопросов, а на nextViewController (это также UITableView) у меня есть несколько вариантов ответов на эти вопросы.Я хочу, чтобы пользователь нажимал на эти вопросы и переходил к nextViewController, выбирал ответ и отображал этот ответ под вопросом в cell.detailTextLabel rootViewController.
Я могу получить ответ, но когда я отображаю его в rootViewController, ответ отображается во всех строках.Не уверен, как это сделать.
Ниже приведен мой код на rootViewController.Буду признателен, если кто-нибудь может помочь мне в этом.Спасибо!
#import "RootViewController.h"
#import "NextViewController.h"
#import "xxxAppDelegate.h"
@implementation RootViewController
@synthesize questions;
@synthesize questAns;
@synthesize aNote;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"xxx";
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Submit" style:UIBarButtonItemStyleBordered target:self action:@selector(SubmitBtn:)] autorelease];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Clear" style:UIBarButtonItemStyleBordered target:self action:@selector(ClearBtn:)] autorelease];
questions = [[NSArray alloc] initWithObjects:@"Question 1", @"Question 2", @"Question 3", nil];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.tableView reloadData];
}
#pragma mark -
#pragma mark Table view data source
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [questions count];
}
// Customize the appearance of table view cells.
- (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] autorelease];
}
// Configure the cell.
cell.textLabel.text = [questions objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
xxxAppDelegate *mainDelegate = (xxxAppDelegate *)[[UIApplication sharedApplication]delegate];
cell.detailTextLabel.text = mainDelegate.MainLocLbl;
NSLog(@"Indexpath.row on root %d", indexPath.row);
NSLog(@"detail text %@", mainDelegate.MainLocLbl);
return cell;
}
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NextViewController *detailViewController = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
// ...
// Pass the selected object to the new view controller.
//questAns = [questions objectAtIndex:indexPath.row];
//detailViewController.answers = questAns;
xxxAppDelegate *mainDelegate = (xxxAppDelegate *)[[UIApplication sharedApplication]delegate];
detailViewController.aNote = mainDelegate.MainLocLbl;
NSLog(@"dtl ans %@", detailViewController.aNote);
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
#pragma mark -
#pragma mark Memory management
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end