jaytrixz
jaytrixz

Reputation: 4079

How can I add and store data in a UITableView?

I'm creating an app that inserts values to a tableview. I also want to add the timestamp on when the value is added to the table. The scenario would be this:

  1. I write some random text in a text field.
  2. I push a button
  3. The text from the text field is saved in the table together with the time I tapped the button.
  4. Done.

Upvotes: 0

Views: 1402

Answers (2)

valapuramRaees
valapuramRaees

Reputation: 11

(NSString *)dataFilePath {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(
                            NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    return [documentsDirectory stringByAppendingPathComponent:kFilename];
}

 (void)applicationWillTerminate:(NSNotification *)notification {
    NSMutableArray *array = [[NSMutableArray alloc] init];
    [array addObject:field1.text];
    [array addObject:field2.text];
    [array addObject:field3.text];
    [array addObject:field4.text];
    [array writeToFile:[self dataFilePath] atomically:YES];
    [array release];
}

Upvotes: 1

Shanti K
Shanti K

Reputation: 2918

Depending on how large your data is, you can store it in a plist, or sqlite3. Here's a link that might be useful: http://www.bogotobogo.com/XcodeSDK-Chapter10.html

Upvotes: 0

Related Questions