1

UPDATE Just resetted al Simulators Data and now it works fine.

I'll appreciate any help :)

My app writes data to a Data.plist file in a subfolder of Documents. I added an NSLog to find out the path so I can check it. I finded and the plist is good. I tried it in a iPad Air. Another page has a "Load" button for loading the plist data and placing it in a textfield. In the iPad Air the info is loaded totally fine.

BUT! I tried it in an iPad 2. And the 2 strings are not loaded. The keys and objects are:

proyectName                       string example
revisarCimiento                   bool   1
tipoCodigoEsfuerzosAdmisibles     string Canada
tipoUnidadMamposteria             string Block
mamposteriaConfinada              bool   0

When the data is loaded, the proyect name doesn't depend on the plist. The bools are fine but the other 2 strings are not loaded.

Here is the code

.h

//
//  factoresCombinacionesCargaViewController.h
//  calcMurosLosas
//
//  Created by Brian Matus on 15/12/14.
//  Copyright (c) 2014 Matus. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface factoresCombinacionesCargaViewController : UIViewController <UITextFieldDelegate>
- (IBAction)loadData:(id)sender;

@property (weak, nonatomic) IBOutlet UITextField *proyectName;
@property (weak, nonatomic) IBOutlet UITextField *levels;
@property (weak, nonatomic) IBOutlet UITextField *revisarCimiento;
@property (weak, nonatomic) IBOutlet UITextField *tipoCodigoEsfuerzosAdmisibles;
@property (weak, nonatomic) IBOutlet UITextField *tipoUnidadMamposteria;
@property (weak, nonatomic) IBOutlet UITextField *mamposteriaConfinada;

+ (void)proyectPath:(NSString *)theString;

@end

.m

#import "factoresCombinacionesCargaViewController.h"
#import "infoGeneralViewController.h"

@interface factoresCombinacionesCargaViewController ()
@end

NSString *proyectPath;
@implementation factoresCombinacionesCargaViewController

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

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)loadData:(id)sender {
    [infoGeneralViewController getProyectNameFromPlist]; //This calls a method that returns a string tho the proyectPath method below.
    [self performSelector:@selector(setLabels) withObject:nil afterDelay:0.1];

}

+ (void)proyectPath:(NSString *)theString {
    proyectPath = theString;
}
-(void)setLabels {
    NSMutableDictionary *plist = [NSMutableDictionary dictionaryWithContentsOfFile:[proyectPath stringByAppendingPathComponent:@"Data.plist"]];

    _proyectName.text = [proyectPath lastPathComponent];

    int leves = [[plist objectForKey:@"numeroNiveles"] integerValue];
    _levels.text = [NSString stringWithFormat:@"%d", leves];

    bool revisarCimiento = [[plist objectForKey:@"revisarCimiento"] boolValue];
    _revisarCimiento.text = [NSString stringWithFormat:@"%s", revisarCimiento ? "Si" : "No"];

    _tipoCodigoEsfuerzosAdmisibles.text = [plist objectForKey:@"tipoCodigoEsfuerzosAdmisibles"];

    _tipoUnidadMamposteria.text = [plist objectForKey:@"tipoUnidadMamposteria"];

    bool mamposteriaConfinada = [[plist objectForKey:@"mamposteriaConfinada"]boolValue];
    _mamposteriaConfinada.text = [NSString stringWithFormat:@"%s", mamposteriaConfinada ? "Si" : "No"];

}
@end

I don't why in the iPad Air the strings are loaded fine but in the iPad 2 not. Thanks for your attention.

  • Where do you set `proyectPath`? i.e. what value are you using? – Paulw11 Dec 16 '14 at 23:32
  • Also, any time I see `performSelector:..afterDelay` it sounds a warning - this is a recipe for timing dependent code - which is what you probably have here since an iPad Air is about 60 times faster than an iPad 2. You should refactor so that you don't need the `performSelector`. Also the use of the class variable `proyectPath` is poor design. – Paulw11 Dec 16 '14 at 23:35
  • `[infoGeneralViewController getProyectNameFromPlist]` calls a method that returns for example /Documents/House1 . `NSString *list` is that string, plus /Data.plist (The file where the data is stored) I changed the delay to `[self setLabels]` but the strings don't load. So I think I have to wrap the plist string into a Object-string. How do I do that? – Brian Matus Dec 17 '14 at 21:28
  • What I am specifically asking about `proyectPath` is are you using hard-coded values (such as /Documents) or are you using code such as in this answer - http://stackoverflow.com/questions/6907381/what-is-the-documents-directory-nsdocumentdirectory It is not safe to hard code simple values. You must use `NSSearchPathForDirectoriesInDomains` – Paulw11 Dec 17 '14 at 21:32
  • Yes, I'm using `proyectPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]stringByAppendingPathComponent:self.proyectNameInfoGeneral.text];` – Brian Matus Dec 17 '14 at 23:21
  • Have you used the debugger to step through your code and see where you are having problems? – Paulw11 Dec 17 '14 at 23:24
  • I do A LOT OF NSLogs while im implementing a new thing. And I can't find the error. I'm thinking that I have to wrap the string of plist into a string that Xcode can use? Here is how the data is stored in the plist [link](https://www.dropbox.com/s/z3nb8nerwmdj5f9/Captura%20de%20pantalla%202014-12-17%20a%20las%2017.40.27.png?dl=0) – Brian Matus Dec 17 '14 at 23:41
  • Don't rely on NSLog. You can't see what is really happening. Set breakpoints and single step through. – Paulw11 Dec 17 '14 at 23:45
  • Yes I do that to. Ok, weird thing. I have implemented a NSLog to get the path where the plist is located, in the iOS Simulator. And I deleted the files, (anyway were te app runs they are created again). And now it seems to work. Thanks for your help. – Brian Matus Dec 17 '14 at 23:49
  • @Paulw11 Thanks for the advice. Im starting to use Xcode and there are a lot of things that I don't know. Thanks for your time – Brian Matus Dec 17 '14 at 23:58

0 Answers0