ios - Plist for persistent data in UITableView between launches -
I have this list, which is called sleeps.plist in my main directory. It seems that
I put it in a UITableView of content .. then I've subclassed the
ViewController with
TableView and I have set it as data source and delegate.
I have made it so that anything in the
NSArray is added to the table (tested with static data).
Now, I want to be able to add data from this plast so that the data remains consistent between the launch (if the user enters more).
Here my code has been inserted in my
viewDidLoad my
ViewController subclass.
NSString * path = [[NSBundle mainBundle] pathForResource: @ "sleeps" type: @ "plist"]; NSDictionary * myDict = [[NSDictionary alloc] initWithContentsOfFile: path]; NSArray * myArray = [myDict objectForKey: @ "root"]; Sleeping = [myArray copy]; // Sleep is a NSRY that has been announced after the @Epplimentation Line NSLog (@ "Points at Point"); NSLog (@ "% @", sleeps);
It reaches the point reached, and then zero ... So I'm not sure what I'm doing wrong, besides the table is empty, do someone tell me in the right direction Could?
Since your plist root is an array and there is no dictionary, your code should be:
NSString * path = [[NSBundle main bundle] pathForResource: @ "sleeps" type: @ "plist"]; NSArray * myArray = [[NSArray alloc] initWithContentsOfFile: Path]; Sleeping = [myArray copy]; // Sleep is a NSRY that has been announced after the @Epplimentation Line NSLog (@ "Points at Point"); NSLog (@ "% @", sleeps); If you want the user to add value then flames should be a NSMutableArray and you MyArray mutableCopy] .
But if you want to continue with additional data, you will need to type the array in a writable folder like the document folder.
Comments
Post a Comment