简体   繁体   中英

Code error in iOS Xcode app

In my Viewcontroller.m I have this code:

- (void)viewDidLoad {

    NSData *dataPdf = [NSData dataWithContentsOfURL:pdfOnline.url];

    //Get path directory
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    //Create PDF_Documents directory
    documentsDirectory = [documentsDirectory stringByAppendingPathComponent:@"PDF_Documents"];
    [[NSFileManager defaultManager] documentsDirectory withIntermediateDirectories:YES attributes:nil error:nil];

    NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, @"My PDF File"];

    [dataPdf writeToFile:filePath atomically:YES];

    [self refresh:self];

    [super viewDidLoad];

    [self.imageView setImage:[UIImage imageNamed:@"Picture.tiff"]];

    [self.scrollView setMaximumZoomScale:10.0f];
    [self.scrollView setClipsToBounds:YES];

    _myBotton.layer.borderWidth =2.0f;
    _myBotton.layer.borderColor = [[UIColor redColor]CGColor];
}

At: NSData *dataPdf = [NSData dataWithContentsOfURL:pdfOnline.url]; I get this error: Use of undeclared identifier 'pdfOnline'

At: [[NSFileManager defaultManager] documentsDirectory withIntermediateDirectories:YES attributes:nil error:nil]; I get this error: Expected ':'

How can I solve these errors? Please help me.

This is what errors means:

You are using pdfOnline but this variables is not defined on the current scope. pdfOnline seems like a property in the class. try using "self.pdfOnline" and also double check the header files contains that property.

t: NSData *dataPdf = [NSData dataWithContentsOfURL:pdfOnline.url]; I get this error: Use of undeclared identifier 'pdfOnline'

You are misspelling this(not sure what you want here)

At: [[NSFileManager defaultManager] documentsDirectory withIntermediateDirectories:YES attributes:nil error:nil]; I get this error: Expected ':'

Try:

[[NSFileManager defaultManager] createDirectoryAtPath:documentsDirectory withIntermediateDirectories:YES attributes:nil error:nil];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM