I am trying to save my data by NSUserDefaults and view it in table view. I have already set four texts data to an array (dataArray) so I can view it in the table view. but I couldn't load the data to the table view. So am I missing something?
Thanks in advance.
-(IBAction)save{
NSUserDefaults *add1 = [NSUserDefaults standardUserDefaults];
[add1 setObject:txt1 forKey:@"txt1"];
[add1 setObject:txt2 forKey:@"txt2"];
[add1 setObject:txt3 forKey:@"txt3"];
[add1 setObject:txt4 forKey:@"txt4"];
[add1 synchronize];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
self.dataArray = [NSArray arrayWithObjects:[prefs objectForKey:@"txt1"], [prefs objectForKey:@"txt2"], [prefs objectForKey:@"txt3"],[prefs objectForKey:@"txt4"] nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
// Set up the number of rows
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [dataArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *string = [dataArray objectAtIndex:indexPath.row];
static NSString *CellIdentifier = @"Cell";
UITableView *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}