Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I populate a textfield with data from a plist
    text
    copied!<p>Im trying to figure out how to populate the textfield in the DVC with data from the plist. I have gotten the data to populate into the tableview cells with know issue. I have not posted the . M for the DVC because simply put. I don't know what to add there ...</p> <p>xml / plist</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; &lt;plist version="1.0"&gt; &lt;array&gt; &lt;dict&gt; &lt;key&gt;cellName&lt;/key&gt; &lt;string&gt;Sharon Lodge No. 327&lt;/string&gt; &lt;key&gt;cellSubtitle&lt;/key&gt; &lt;string&gt;McLean, VA&lt;/string&gt; &lt;key&gt;address&lt;/key&gt; &lt;string&gt;999 Balls Hill Road&lt;/string&gt; &lt;key&gt;webSite&lt;/key&gt; &lt;string&gt;www.website.com&lt;/string&gt; &lt;key&gt;statedCom&lt;/key&gt; &lt;string&gt;Hold meetins on...&lt;/string&gt; &lt;/dict&gt; &lt;dict&gt; &lt;key&gt;cellName&lt;/key&gt; &lt;string&gt;Sharon Lodge No. 327&lt;/string&gt; &lt;key&gt;cellSubtitle&lt;/key&gt; &lt;string&gt;McLean, VA&lt;/string&gt; &lt;key&gt;address&lt;/key&gt; &lt;string&gt;999 Balls Hill Road&lt;/string&gt; &lt;key&gt;webSite&lt;/key&gt; &lt;string&gt;www.website.com&lt;/string&gt; &lt;key&gt;statedCom&lt;/key&gt; &lt;string&gt;Hold meetins on...&lt;/string&gt; &lt;/dict&gt; </code></pre> <p>.h for DVC</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface DetailViewController : UIViewController @property (strong, nonatomic) IBOutlet UILabel *address; @property (strong, nonatomic) IBOutlet UILabel *webSite; @property (strong, nonatomic) IBOutlet UILabel *statedCom; @property (nonatomic, copy) NSDictionary *contactInfo; // added this @end </code></pre> <p>.h for talbleview</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface plistTableViewController : UITableViewController { NSArray *tabledata; } @end </code></pre> <p>.M for Tableview</p> <pre><code>#import "plistTableViewController.h" #import "DetailViewController.h" @interface plistTableViewController () @end @implementation plistTableViewController - (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { NSString *mylist = [[NSBundle mainBundle] pathForResource:@"lodges" ofType:@"plist"]; tabledata = [[NSArray alloc]initWithContentsOfFile:mylist]; NSLog(@"%@", tabledata); [super viewDidLoad]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (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 [tabledata count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; if( cell == nil ) { NSLog(@"Cell Creation"); cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"]; } //Set Data For each Cell cell.textLabel.text = [[tabledata objectAtIndex:indexPath.row]objectForKey:@"cellName"]; cell.detailTextLabel.text = [[tabledata objectAtIndex:indexPath.row]objectForKey:@"cellSubtitle"]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; } -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { </code></pre> <p>added this NSIndexPath *indexPath = [[self tableView] indexPathForSelectedRow]; NSDictionary *contactInfo = tabledata[indexPath.row]; DetailViewController *dvc = (DetailViewController *)[segue destinationViewController]; dvc.contactInfo = contactInfo; dvc.address = [[tabledata objectAtIndex:@"address"]]; // this is wrong but not sure about how to write it correctly. </p> <pre><code>} </code></pre> <p>.m to dvc </p> <pre><code>#import "DetailViewController.h" @interface DetailViewController () @end @implementation DetailViewController @synthesize address,webSite,statedCom; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { self.address =[[tabledata objectAtIndex:address]]; // not sure how to complete this [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end </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