What is the best way to display pdf in objective-c? [closed] - ios

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I need to display pdf documents within my iPad app, I've seen people suggesting loading it within a webview.
I want to know if this is the best\recommended way to display a pdf?

Using a QuickLook.framework you can easly load pdf and disply i just add following easy step for load pdf using QuickLook.framework
Add QuickLook.framework and import in to your class and set it's DataSource in to .h class <QLPreviewControllerDataSource>
Use following method:
-(NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
{
return 1;
}
- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
return [NSURL fileURLWithPath:self.pdfFilePath]; // here is self.pdfFilePath its a path of you pdf
}
and for load set Button Action:
-(IBAction)LoadPdf
{
QLPreviewController* preview = [[[QLPreviewController alloc] init] autorelease];
preview.dataSource = self;
[self presentModalViewController:preview animated:YES];
}

Two easiest way to that
UIWebView
QLPreviewController

Related

iOS Swift - Singleton data persistance [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am developping an application that saves informations about the logged-in user in CoreData and singleton class. After the user log-in, I'm fetching data from coredata and set the variables from the singleton.
My question:
If the app receives memory warning issue, and the data from the singleton will be released, my app will crash. What can I do in this situation?
Thanks!
Let's say you have a local property named NSArray *myArray in singleton's .m file where you store all the needed data. All you need to do is to add a method in header file which returns that array if is not nil, and in case of nil make it reload from storage and return.
Also override - (void)didReceiveMemoryWarning method and save the data in case of memory warning.
Here is a sample code written in objective-c:
//Singleton.h file
- (NSArray *)storedData;
//Singleton.m file
#property NSArray *myArray;
...
- (NSArray *)storedData
{
if (_myArray == nil)
_myArray = [self fetchMyArrayFromLocalStorage];
return _myArray;
}
- (NSArray *)fetchMyArrayFromLocalStorage
{
//Some code to fetch data from local storage
}
- (void)saveMyArrayToLocalStorage
{
//Code to save _myArray to local storage
}
- (void)didReceiveMemoryWarning
{
[self saveMyArrayToLocalStorage];
_myArray = nil; //Remove array if is needed
[super didReceiveMemoryWarning];
}
Now you'll always get the data you needed simply by calling method:
[[mySingleton sharedInstance] storedData]
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
Your ViewController would have this method by default, and before your app crash, this method will execute automatically, you should write some code in this method to make sure your data can be saved in device, and then release it.

iOS UIViewControler singleton and how to use helper class? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I follow the online way to write singleton, each into SecondViewController, address of the print is the same , but why UISwitch interface is initialized ? I was into the original UIViewController? someone was also suggested to write helper class. Everthing is beginning, it is not very clear, Is there any Demo or explain the basic principles?How to write the code depend on second image?
enter image description here
enter image description here
Try this code
static SecondViewController *sharedVCInstance = nil;
+ (SecondViewController *)sharedInstance
{
static dispatch_once_t onceToken = 0;
dispatch_once (&onceToken, ^{
if(sharedVCInstance == nil)
sharedVCInstance = [[SecondViewController alloc] init];
});
return sharedVCInstance;
}

How to load interstitial ads when Navigation Back Button Pressed and Some Click Event? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am new to iOS development. I am adding an interstitial ads when ViewDidLoad but I want to show interstitial ads when an user clicks ten times in my application, is that possible? If it is possible then please help me finding a solution. My Application contains HMSegmentedControll and it has ten different UITableView. And I also want to display these ads when NavigationBar back button is pressed. Could anyone help me with this?
It is Possible like as SharedPreference in Android
Make One Global Variable NSObject like as
GlobalVariable.h File
#property (assign) int touchCount;
+ (TouchCount *)getInstance;
#end
and GlobalVariable.m File
#synthesize touchCount;
static TouchCount *instance = nil;
+(TouchCount *)getInstance
{
#synchronized(self)
{
if(instance==nil)
{
instance= [TouchCount new];
}
if (instance.touchCount ==10)
{
instance.touchCount=0;
instance= [TouchCount new];
}
}
return instance;
}
And Use this Instance when You Want to Touch Count import GLobalVariable.hlike as
TouchCount *obj=[TouchCount getInstance];
Whell u can add some global value than counts "back taps"
in GlobalVariables.h file something like this:
extern int PRJ_back_touches_count;
.m:
int PRJ_back_touches_count;
Than e.g. in viewWillDisappear method PRJ_back_touches_count++
On viewDidAppear u can handle the PRJ_back_touches_count actual value

Empty NSMutableArray after adding elements [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Here's my project: https://github.com/a8b/musicManager/tree/master/musicManager
I have issue with addSongToLibrary method in MusicCollection.m - it doesn't add songs with [library addSong:song]
To simplify your code for clarity, it's doing this:
-(void) addSongToLibrary:(Song *)song {
for (Song *song in library.songs) {
NSLog(#"%#", song);
}
[library addSong:song];
}
}
You are declaring a variable with the same name as a method parameter, so it is hiding the value passed in.
Well you commented out the following code
/*-(instancetype) init {
self = [super init];
if (self) {
library.songs = [NSMutableArray array];
[library addSong:[Song new]];
}
return self;
}*/
so library is never instaniated, either you uncommented it , or in viewDidLoad you need to add library.songs = [NSMutableArray array]; otherwise it will be nil.

Dynamic cast to a custom class in objective C [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
In NewTaskViewController.h, delegate was declared to be a property of type id.
Does the typecast below make delegate point to the object of type ViewController?
#import "NewTaskViewController.h"
#import "ViewController.h"
#implementation NewTaskViewController
- (IBAction)saveTask:(id)sender {
if ([self.textField.text length] == 0)
return;
ViewController *tasksListView = (ViewController *)self.delegate;
[tasksListView.tasks addObject:self.textField.text];
[self close:sender];
}
- (IBAction)close:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
#end
The cast tells the compiler that you want to use the delegate object as if it were a ViewController. If it really is one, you're OK. If it's not, bad things will happen at run-time. That is, the cast doesn't do any kind of conversion.

Resources