Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Load PDF in UIViewcontroller

Hello!

I am creating a simple PDF reader. All of the sample codes that i saw i had to tap a button to open the pdf. But what i really want is to open the pdf file when te app runs, without tapping a button.

This is my viewDidLoad code in ViewController.m:


- (void)viewDidLoad

{

[superviewDidLoad];

NSString *path = [[NSBundlemainBundle] pathForResource:@"399_KIT_ELEITORAL_BX_01"ofType:@"pdf"];

PageViewController *page = [[PageViewControlleralloc] initWithPDFAtPath:path];

[selfpresentViewController:page animated:YEScompletion:NULL];

}


When i run the app, it doesn`t show the pdf.


Thank you!

Posted on Feb 3, 2014 4:58 AM

Reply
10 replies

Feb 3, 2014 5:15 AM in response to msuper69

I put the code in ViewWillAppear, but it still doesn`t appear:

This is the whole code:


@interfaceViewController ()


@end


@implementation ViewController


- (void)viewDidLoad

{

[superviewDidLoad];

}


- (void)viewWillAppear

{

NSString *path = [[NSBundlemainBundle] pathForResource:@"399_KIT_ELEITORAL_BX_01"ofType:@"pdf"];

PageViewController *page = [[PageViewControlleralloc] initWithPDFAtPath:path];

[selfpresentViewController:page animated:YEScompletion:NULL];

}


- (void)didReceiveMemoryWarning

{

[superdidReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}


@end


Thank you!

Feb 3, 2014 5:23 AM in response to msuper69

- (void)viewWillAppear

{

[super viewWillAppear];

NSString *path = [[NSBundlemainBundle] pathForResource:@"399_KIT_ELEITORAL_BX_01"ofType:@"pdf"];

PageViewController *page = [[PageViewControlleralloc] initWithPDFAtPath:path];

[selfpresentViewController:page animated:YEScompletion:NULL];

}



It says that:

No visible @interface for 'UIViewController' declares the selector 'viewWillAppear'

Feb 3, 2014 5:33 AM in response to LeoRegin

You have to use a BOOL in place of animated. For example, [super viewWillAppear:YES];


You've also left off the ending semi-colon which is a syntax requirement of Objective-C.

Statements end with a semi-colon in Objective-C and that line is missing the semi-colon.


You really need to review the basics of Objective-C as these are all very basic concepts.

Feb 3, 2014 5:39 AM in response to msuper69

I'm sorry for the mistakes, i am new im Objective-C, but i think i will only learn programming lwhile i do this. I apreciate your help!


This is the new code:


- (void)viewWillAppear

{

[superviewWillAppear:YES];

NSString *path = [[NSBundlemainBundle] pathForResource:@"399_KIT_ELEITORAL_BX_01"ofType:@"pdf"];

PageViewController *page = [[PageViewControlleralloc] initWithPDFAtPath:path];

[selfpresentViewController:page animated:YEScompletion:NULL];

}


But it still doesn't show the pdf...


I need your help to finish this task.


Thank you!

Load PDF in UIViewcontroller

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.