A
A
artursk2016-03-02 05:30:19
iOS
artursk, 2016-03-02 05:30:19

How to pass custom Objects saved via NSUserdefaults to a table cell?

Guys help, after solving this problem I will post it on this page
http://ru.stackoverflow.com/questions/498609/%d0%a...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Pavlenko, 2016-03-05
@pavlenkovs

Initialize NSUserDefaults with the [NSUserDefaults standardUserDefaults] method.
Then, in the cellForItemAtIndexPath method, after initializing the cell, you take the object you want from your NSUserDefaults.
Hope I could help.
For example:

@interface MyViewController ()

@property (nonatomic, weak) IBOutlet tableView *tableView;
@property (nonatomic, strong) NSUserDefaults *userDefaults;

@end

- (UITableViewCell *)tableView:(UITableView *)tableView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID = @"cell";
    
   MyTableViewCell *cell = [tableView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    
    cell.myProperty = [self.userDefaults objectForKey:@"myObject"];
    
    return cell;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question