Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableView SDK add array
    primarykey
    data
    text
    <p>What I'm trying to do is an app that lets you type in a task to a field, Press insert and see it in the table below it. I have my table (<code>*table</code>), my field (<code>*taskField</code>), My button (<code>*insert</code>) and my array (<code>*tasks</code>). I run the app, type something in and press insert but nothing shows up in the table. I also believe i have all my "IB" stuff set up right.</p> <p>here is my code:</p> <pre><code>NSString *docPath() { NSArray *pathList = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); return [[pathList objectAtIndex:0] stringByAppendingPathComponent:@"data.td" ]; } #import "CookViewController.h" @interface CookViewController () @end @implementation CookViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } - (IBAction)addRec:(id)sender { NSString *t=[taskField text]; if ([t isEqualToString:@""]) { return; } [tasks addObject:t]; [table reloadData]; [taskField setText:@""]; [taskField resignFirstResponder]; [tasks writeToFile:docPath() atomically:YES]; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { [tasks removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; } } #pragma mark - Table View management - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [tasks count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *c= [table dequeueReusableCellWithIdentifier:@"Cell"]; if (!c) { c= [[ UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; } NSString *item = [tasks objectAtIndex:[indexPath row]]; [[c textLabel] setText:item]; return c; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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