FGallery issue on iPhone - objective-c

I am trying to implement FGallery for displaying images in grid view. But i am facing one problem which i explained below:
When i try to load images with below method it works,
NSString *string1 = #"user/name/Library/ApplicationSupport/../Documents/image1.jpg";
NSArray *array = [[NSArray alloc]initWithObjects: string1,nil];
The above methods completely works withour error.
But When i try to load image with the below method i get only blank image,
NSString *string1 = (NSString *) [[self.allImagePath valueForKey#"image_Path"] objectAtIndex:0];
NSArray *array = [[NSArray alloc]initWithObjects: string1, nil];
The above method load blank images in both grid view and thumbnail view. Please guide me for solution.

Related

Display local images in gallery objective-c

I would like to display images that were saved locally from the app to the iPhones Documents directory in a gallery layout, similar to Photos.app with the thumbnails (4 columns, as many rows necessary). I have tried some open sourced code, including CHGridView, but most of them are several years old and not working with iOS 7. I would prefer to not use open sourced code if possible anyway.
I am able to store my files in an NSMutableArray using the following method:
- (NSMutableArray *)arrayOfImages
{
int count;
NSMutableArray *array = [NSMutableArray array];
for (count = 0; count < 500; count++) //assuming no more than 500 items saved.
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *fileName = [NSString stringWithFormat:#"img%d", count]; //images are called img0.png, img1.png, etc
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:fileName];
UIImage *checkImage = [[UIImage alloc] initWithContentsOfFile:filePath];
if (checkImage != nil) //if there is an image there, add it to array
{
[array addObject:checkImage];
}
}
return array;
}
UICollectionView was added in iOS6 and is designed to do exactly what you are describing. The code needed is similar to the code for a UITableView, but instead of managing a 1D collection like a table view, the collection view manages a 2D collection of objects.

Cannot change mutable array?

Ok so I have been stuck on this for a while even though it's a simple problem, I am trying to add an NSDictionary to an array however when calling the addObject method on the array the program crashes claiming I am sending a mutating method to an immutable object.
my code looks like:
- (IBAction)btnSaveMessage:(id)sender {
//Save The Message and Clear Text Fields
NSMutableDictionary *newMessageDictionary = [[NSMutableDictionary alloc] init];
[newMessageDictionary setObject:#"plist test title" forKey:#"Title"];
[newMessageDictionary setObject:#"plist subtitle" forKey:#"Subtitle"];
[newMessageDictionary setObject:#"-3.892119" forKey:#"Longitude"];
[newMessageDictionary setObject:#"54.191707" forKey:#"Lattitude"];
NSMutableArray *messagesArray =[[NSMutableArray alloc]init];
//Load Plist into array
NSString *messagesPath = [[NSBundle mainBundle] pathForResource:#"Messages"
ofType:#"plist"];
messagesArray = [NSArray arrayWithContentsOfFile:messagesPath];
[messagesArray addObject:newMessageDictionary]; //this causes crash
//write messagesarray to file
NSString *plistPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES) lastObject];
plistPath = [plistPath stringByAppendingPathComponent:#"usersMessages.plist"];
[messagesArray writeToFile:plistPath atomically:YES];
So I understand that I am trying to add to what the compiler see's as an immutable array but I declared it as Mutable?
Whats going on? :(
You are re-initializing messagesArray with
[NSArray arrayWithContentsOfFile:messagesPath]
Making it not mutable. Try:
[NSMutableArray arrayWithContentsOfFile:messagesPath];
You are overwriting your NSMutableArray with an NSArray in this line
messagesArray = [NSArray arrayWithContentsOfFile:messagesPath];
The class method arrayWithContentsOfFile: is returning just an NSArray and not an NSMutableArray.
If you want the content of the file mutable you can do this:
NSMutableArray *messagesArray = [[NSArray arrayWithContentsOfFile:messagesPath] mutableCopy];
and you can remove the previous declaration
NSMutableArray *messagesArray =[[NSMutableArray alloc]init];
now.

Populate an NSArray via an NSDictionary which is populated via a .plist

Here is the code:
-(void)viewDidLoad {
[super viewDidLoad];
//Verb data read, sorted and assigned to a dictionary
NSBundle *bundle = [NSBundle mainBundle];
NSString *plistPath = [bundle pathForResource:#"VerbDictionary" ofType:#"plist"];
NSDictionary *verbDictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
NSArray *verbs = [verbDictionary allKeys];
NSArray *vSorted = [verbs sortedArrayUsingSelector:#selector(compare:)];
NSString *selectedVerb = [vSorted objectAtIndex:0];
NSArray *vArray = [verbDictionary objectForKey:selectedVerb];
self.verbArrayData = [[NSArray alloc] initWithArray:vArray];
}
Here is a screenshot of the Error message I'm getting:
(from https://plus.google.com/u/0/113629344949177123204/posts/SwHzXL6kvvJ)
The self.verbArrayData is not populating from the vArray. self.verbDataArray is nil and it shouldn't be.
I have tried this from scratch and I have done this before, actually, in the past, but via iOS 4 and Release/retain memory management. This is the first pure iOS 5 ARC app I have started.
Any ideas?
I figured it out... But I am not sure why it works. Self.verbArrayData is invalid. However, just verbArrayData works just fine. So, I changed self.verbArrayData = [[NSArray...] TO just verbArrayData = [[NSArray...] and it compiled and ran fine. So, self.verbArrayData is the getter not the setter in this case; I think. THanks - –

Unable to store an UIImage in an NSMutableArray

I am trying to store a UIImage in an NSMutableArray but it doesn t work, here is the line I am using:
[images addObject:QRImage];
There are no compilation errors, but when I debug the app I see that the NSMutableArray has 0 objects. i.e. the image was not added.
I suspect your NSMutableArray is not properly initialized. Try this:
NSMutableArray *images = [[NSMutableArray alloc] init];
// ...
[images addObject:QRImage];

Change from a NSMutableArray to a .plist

I have been working through several tutorials on uitableviews.
I have put, as instructed, all the info into a 'listofitems' as below
listOfItems = [[NSMutableArray alloc] init];
NSArray *countriesToLiveInArray = [NSArray arrayWithObjects:#"Iceland", #"Greenland", #"Switzerland", #"Norway", #"New Zealand", #"Greece", #"Rome", #"Ireland", nil];
NSDictionary *countriesToLiveInDict = [NSDictionary dictionaryWithObject:countriesToLiveInArray forKey:#"Countries"];
NSArray *countriesLivedInArray = [NSArray arrayWithObjects:#"India", #"U.S.A", nil];
NSDictionary *countriesLivedInDict = [NSDictionary dictionaryWithObject:countriesLivedInArray forKey:#"Countries"];
[listOfItems addObject:countriesToLiveInDict];
[listOfItems addObject:countriesLivedInDict];
This creates a sectioned table view. I would like to know how to change it into a .plist instead of typing it all out into the RootViewController.m. I would still like it to be in a sectioned tableview.
Is there a simple method for changing from this NSMutableArray,NSArray and NSDictionary to a plist?
There's a simple method for this writeToFile:atomically::
[listOfItems writeToFile:destinationPath atomically:YES];
This will automatically create a file with plist inside it.
that sorta depends on what you want in a plist, and what you put into it. if the entries and contents are all CFPropertyList types (CFString,CFDate,CFData,CFDictionary,CFArray,CFNumber...) then just create it with something like CFPropertyListCreateDeepCopy.
if you have non-convertible custom objects (e.g., your own NSObject subclasses), then see the cocoa archiving topics.
This is the simple function end hear relization
This is function is updating NSArray
- (void) WriteRecordToFile:(NSMutableDictionary*)countDict {
// Here to write to file
databasePathCallCount = #"plist path";
NSMutableArray *countArray = [NSMutableArray arrayWithContentsOfFile:databasePathCallCount];
if(countArray)
[countArray addObject:countDict];
[countArray writeToFile:databasePathCallCount atomically:NO];
}