Note that there are some explanatory texts on larger screens.

plurals
  1. POPush Uiview and populate with data
    text
    copied!<p>I'm creating a simple app that stores data into a sqlite database and retrieves data from it. I'm able to store data and I'm also able to populate a UITableView with all the data, showing a field (name) in the prototype cell. What I'm trying to do now is to open a view on tap to show ALL the details. So I did set up a viewController with 3 fields to be filled in, but I don't know how to transfer data between that cell to the new view. </p> <p>Here's my code:</p> <pre><code>#import "RootViewController.h" #import "AppDelegate.h" #import "Inserimento_Esame.h" #import "Dettagli_Esame.h" @interface RootViewController () @end @implementation RootViewController @synthesize nome,crediti,voto; - (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; NSString *docsDir; NSArray *dirPaths; dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); docsDir = [dirPaths objectAtIndex:0]; databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"Esami.sqlite"]]; dataList = [[Data alloc] init:databasePath]; } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {return YES;} #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. return [dataList getSize]; } - (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]; } NSDictionary *itemAtIndex = (NSDictionary *)[dataList objectAtIndex:indexPath.row]; cell.textLabel.textColor = [UIColor whiteColor]; cell.textLabel.text = [itemAtIndex objectForKey:@"nome"]; cell.detailTextLabel.textColor = [UIColor whiteColor]; cell.detailTextLabel.text = [itemAtIndex objectForKey:@"voto"]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self performSegueWithIdentifier:@"DETTAGLI" sender:indexPath]; } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"DETTAGLI"]) { NSLog(@"Dettagli"); Dettagli_Esame *destination = [segue destinationViewController]; NSIndexPath * myIndexPath = [self.tableView indexPathForSelectedRow]; NSDictionary *itemAtIndex = (NSDictionary *)[dataList objectAtIndex:myIndexPath.row]; destination.Dett = itemAtIndex; // I THINK I MUST PUT HERE MY MISSING CODE } } @end EDIT3 #import "Dettagli_Esame.h" @interface Dettagli_Esame () @end @implementation Dettagli_Esame @synthesize nome; @synthesize crediti; @synthesize voto; @synthesize Dett; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad {[super viewDidLoad];} EDIT5-6: -(void)viewDidAppear:(BOOL)animated{ NSString *docsDir; NSArray *dirPaths; NSLog(@"Dettagli Esame"); dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); docsDir = [dirPaths objectAtIndex:0]; databasePath = [[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent: @"Esami.sqlite"]]; dataList = [[Data alloc] init:databasePath]; nome.text = [Dett objectForKey:@"nome"]; crediti.text = [Dett objectForKey:@"crediti"]; voto.text = [Dett objectForKey:@"voto"]; NSLog(@"Dettagli Esame: %@", self.Dett); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload