1

I store the information of a user in a variable of type NSUserDefaults when the user clicks on the save button. I would like the launch of the application, the settings can be saved in the corresponding cells filled. So here's what I did in the corresponding file in the viewDidLoad method.

- (void)viewDidLoad
{
    // [super viewDidLoad];
// Do any additional setup after loading the view.

    if (self.navigationPaneBarButtonItem)
            [self.navigationBar.topItem setLeftBarButtonItem:self.navigationPaneBarButtonItem
                                                                                            animated:NO];

    //Initialise IndexPath
    NSIndexPath *indexPathBroker = [NSIndexPath indexPathForRow:0 inSection:0];
    NSIndexPath *indexPathPort = [NSIndexPath indexPathForRow:1 inSection:0];

    NSUserDefaults *defaultConf;
    defaultConf=[NSUserDefaults standardUserDefaults];
    NSString * broker =[defaultConf stringForKey:@"broker"];
    NSString *port= [defaultConf stringForKey:@"port"];
    NSLog(@"Brokerdidload: %@ et Portdidload: %@",broker,port);

    //Create strings and integer to store the text info
    ConfigDetailEditTableCell *editCellBroker = (ConfigDetailEditTableCell *)[_tableView cellForRowAtIndexPath:indexPathBroker];
    ConfigDetailEditTableCell *editCellPort = (ConfigDetailEditTableCell *)[_tableView cellForRowAtIndexPath:indexPathPort];


    //set data
          editCellPort.EditCellValue.text =port;
    editCellBroker.EditCellValue.text=broker;
  //  [editCellBroker.EditCellValue setText:broker];
  //   [[editCellPort textLabel] setText:port];
  //  [[editCellBroker textLabel] setText:broker];
   // [[editCellPort textLabel] setPlaceholder:port];
   // [[editCellBroker textLabel] setPlaceholder:broker];
   // editCellPort.EditCellValue.text =*/


    NSLog(@"editCellPort.EditCellValue: %@ et editCellBroker.EditCellValue: %@",editCellPort.EditCellValue.text,editCellBroker.EditCellValue.text);

}

Variables in the broker and port, I have information but when I try to update the cell it does not work. The last NSLog that I am Null references

How to remedy????

Thank you in advance

4

2 に答える 2

1

Instead of trying to set the value of cell from viewDidLoad you should do it in cellForRowAtIndexPath: dataSource method of tableView

- (void)viewDidLoad
{
    // [super viewDidLoad];
// Do any additional setup after loading the view.

    if (self.navigationPaneBarButtonItem)
            [self.navigationBar.topItem setLeftBarButtonItem:self.navigationPaneBarButtonItem

   //Rest are not needed

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
       //Initialize cell


        NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
        NSString * broker =[defaults stringForKey:@"broker"];
        NSString *port= [defaults stringForKey:@"port"];

        cell.EditCellValue.text = indexPath.row==0?broker:port;

        return cell;

}
于 2013-03-25T10:49:12.283 に答える
0

You can also use the free Sensible TableView framework to automatically fetch your data from NSUserDefaults and display it on a table view. It will also automatically save whatever data has been entered back to NSUserDefaults. Comes in very handy.

于 2013-03-25T19:04:26.990 に答える