changing up some code in 'DraggableViewBackground.m' - arrays

Github Source URL: https://github.com/cwRichardKim/RKSwipeCards
So, I need to change up some code in 'DraggableViewBackground.m'.
rather than an array of text as is on the stock source code, I need to create an array of images...
Stock section:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[super layoutSubviews];
[self setupView];
exampleCardLabels = [[NSArray alloc]initWithObjects:#"first",#"second",#"third",#"fourth",#"last", nil]; //%%% placeholder for card-specific information
loadedCards = [[NSMutableArray alloc] init];
allCards = [[NSMutableArray alloc] init];
cardsLoadedIndex = 0;
[self loadCards];
}
return self;
}
I have looked at various implementations of image array, but still comes up with some errors what I can't resolve.
this is my edited code for the array:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[super layoutSubviews];
[self setupView];
exampleCardGraphics = [[NSArray alloc]initWithObjects:00_quote#2x.png, 01_quote#2x.png,02_quote#2x.png,03_quote#2x.png,04_quote#2x.png,05_quote#2x.png,06_quote#2x.png,07_quote#2x.png,08_quote#2x.png,09_quote#2x.png,10_quote#2x.png,11_quote#2x.png,12_quote#2x.png,13_quote#2x.png,14_quote#2x.png,15_quote#2x.png,16_quote#2x.png,17_quote#2x.png,18_quote#2x.png,19_quote#2x.png,20_quote#2x.png,21_quote#2x.png,22_quote#2x.png,23_quote#2x.png,24_quote#2x.png,25_quote#2x.png,26_quote#2x.png,27_quote#2x.png,28_quote#2x.png,29_quote#2x.png,30_quote#2x.png,31_quote#2x.png,32_quote#2x.png,33_quote#2x.png,34_quote#2x.png,35_quote#2x.png,36_quote#2x.png,37_quote#2x.png,38_quote#2x.png,39_quote#2x.png,40_quote#2x.png,41_quote#2x.png,42_quote#2x.png,43_quote#2x.png,44_quote#2x.png,45_quote#2x.png,46_quote#2x.png,47_quote#2x.png,48_quote#2x.png,nil]; //%%% placeholder for card-specific information
loadedCards = [[NSMutableArray alloc] init];
allCards = [[NSMutableArray alloc] init];
cardsLoadedIndex = 0;
[self loadCards];
}
return self;
}
I get returned "Invalid suffix '_quote' on integer constant"
How would I resolve this to get images pulled into the array, and subsequently one image for each swipe card ?
I have changed a few other things, however only instance names, which have been changed accordingly in corresponding files, so the build still succeeds but I can't get the image array to work.
Please help!
Thanks.

Related

Call an array from object

-(NSMutableArray *) botanicalPlant {
if (_botanicalPlant == nil) {
_botanicalPlant = [[NSMutableArray alloc] initWithObjects:#"Abelia", nil];
}
return _botanicalPlant;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.botanicalPlantName = [[BotanicalPlant alloc] init];
self.botanicalPlantNameLabel.text = []
}
I know this may be a simple question but Im stuck on this one. I have an array in NSObject of Botanical I just don't know how to call it in the viewDidLoad method for it to show up in my main view controller. I don't know what to put in the brackets to assign it to the text of the label.
You haven't shown enough code to answer your question for sure. But if botanicalPlant is a mutable array property on the BotanicalPlant class, then you could do something like:
BotanicalPlant *myBotanicalPlant = [[BotanicalPlant alloc] init];
NSMutableArray *namesArray = myBotanicalPlant.botanicalPlant;
self.botanicalPlantNameLabel.text = [namesArray firstObject];
Try This:
In your viewDidLoad method
NSMutableArray *arrayFromBotanicalMethod = [self botanicalPlant];
// Then set the text label from your new array that you created
self.botanicalPlantNameLabel.text = [arrayFromBotanicalMethod objectAtIndex:0];
This code is based on the limited information you provided. You basically create another array that will hold the returned array from your botanicalPlant method. Then you use the objectAtIndex message on the new array to get the text for the label.
Hope it helps.

ZUUIRevealControler: Issue in size of rearViewContriller's View While running in iPhone(Retina 4Inch)

I got an issue with ZUUIRevealController.
ISSUE:
While running in iPhone (Retina 4Inch) simulator the height of [rearViewController View] is still
frame = (0 0; 320 480)
instead of
frame = (0 0; 320 568).
So the rear view seem to be truncated.
But this issue is not there for frontViewController.
Here is how I added my rearViewController and frontViewController
viewCont1 *frontViewController = [[viewCont1 alloc]initWithNibName:#"viewCont1" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
viewCont2 *rearViewController = [[viewCont1 alloc] initWithNibName:#"viewCont1" bundle:nil];
revealController = [[RevealController alloc] initWithFrontViewController:navigationController rearViewController:rearViewController];
revealController.delegate = rearViewController;
Any one ever came across such an issue??
Any help appreciated.
I figured that out. We have to keep both the front and rear VC as navigationController
frontVc *frontViewController = [[frontVc alloc]initWithNibName:#"frontVc" bundle:nil];
frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
rearVc *rearViewController = [[rearVc alloc] initWithNibName:#"rearVc" bundle:nil];
rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];
revealController = [[RevealController alloc] initWithFrontViewController:frontNavigationController rearViewController:rearNavigationController];

CoreData leaks with fetched results arrays

I'm using CoreData to store objects like cars, trips, data recorded from GPS, etc.
When I fetch what I want to show a list of trips, some stats for a trip, or add a new car in my settings view controller, I use pretty much this kind of request:
- (void)getDataTrip
{
// Fetched data trips.
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"DataTrip" inManagedObjectContext:[self managedObjectContext]];
[fetchRequest setEntity:entity];
// Set predicate and sort orderings...
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:#"timestamp" ascending:YES];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[fetchRequest setSortDescriptors:sortDescriptors];
[sortDescriptors release];
[sortDescriptor release];
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"idTrip = %#", self.idTrip];
[fetchRequest setPredicate:predicate];
// Execute the fetch -- create a mutable copy of the result.
NSError *error = nil;
NSMutableArray *mutableFetchResults = [[self.managedObjectContext executeFetchRequest:fetchRequest error:&error] mutableCopy];
if (mutableFetchResults == nil) {
// Handle the error.
NSLog(#"failed with error: %#", error);
}
// Set the array.
[self setDataTripArray:mutableFetchResults];
// Memory management.
[fetchRequest release];
[mutableFetchResults release];
}
Sometimes, I have leaks when I do the [self setDataTripArray:mutableFetchResults]; and sometimes not. In this case, when I get the data for a trip, it leaks all the time when I use the navigation controller to come back to the root view controller (displaying a list of trips), and/or when I change tab.
Anyway, it just leaks and it's all the time coming from fetching data from CoreData, and give this array to my local array var.
Please let me know if you see how to fix this! It made the app crash after a while.
Thanks!
SOLUTION
I found that I do a retain on my object dataTripArray object when creating another UIViewController that I use to create graphs for my scroll view.
- (void)loadScrollViewWithPage:(int)page
{
if (page < 0)
return;
if (page >= kNumberOfPages)
return;
// Replace the placeholder if necessary.
GraphController *controller = [self.graphControllers objectAtIndex:page];
if ((NSNull *)controller == [NSNull null])
{
controller = [[GraphController alloc] initWithPageNumber:page data:[self.dataTripArray retain]];
[self.graphControllers replaceObjectAtIndex:page withObject:controller];
[controller release];
}
// Add the controller's view to the scroll view.
if (controller.view.superview == nil)
{
CGRect frame = _scrollView.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
controller.view.frame = frame;
[self.scrollView addSubview:controller.view];
}
}
I just removed the retain and the leak is no longer coming up. Fixed!

Saving arrays of iOS Apps

I would like to know how to save arrays of my iOS app. I used a method, but it only saved on my iPod Touch. I'd tested on iPad and it didn't work.
What I need is a code to save my app array on any device...
Anyone can help me?
Here is the code:
myAppViewController.h:
- (NSString *)GetApplicationDocumentsDirectory;
- (void)applicationWillTerminate:(NSNotification *)notification;
myAppViewController.m:
-(NSString*) GetApplicationDocumentsDirectory {
static NSString* documentsDirectory = nil;
if (documentsDirectory == nil) {
documentsDirectory = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES)
objectAtIndex:0] retain];
}
NSString *fullFileName = [NSString stringWithFormat:#"%#/TarefasSalvas.plist", documentsDirectory];
return fullFileName;
}
- (void)applicationWillTerminate:(NSNotification *)notification{
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:lisTitulos];
[array addObject:lisImagens];
[array addObject:lisData];
[array addObject:lisDetalhes];
[array writeToFile:[self GetApplicationDocumentsDirectory] atomically:YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
NSString *filePath = [self GetApplicationDocumentsDirectory];
//if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
if (array != nil){
lisTitulos = [array objectAtIndex:0];
lisImagens = [array objectAtIndex:1];
lisData = [array objectAtIndex:2];
lisDetalhes = [array objectAtIndex:3];
}
else {
NSDate *date = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setLocale:[NSLocale currentLocale]];
[dateFormat setDateFormat:#"dd/MM/YYYY"];
NSString *dateNow = [dateFormat stringFromDate:date];
lisTitulos = [[NSMutableArray alloc] initWithObjects:#"Titulo",nil];
lisImagens = [[NSMutableArray alloc] initWithObjects:#"0.png",nil];
lisData = [[NSMutableArray alloc] initWithObjects:dateNow,nil];
lisDetalhes = [[NSMutableArray alloc] initWithObjects:#"",nil];
}
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:app];
}
Thanks
It is possible that you're just sending the app to the background and not terminating them. On such occasion, applicationWillTerminate: will not be called. That seems to be the likely cause as the rest of the code looks fine.
And your GetApplicationDocumentsDirectory seems a bit strangely named as it gets the path to the file in which the array is stored. In addition to that,
NSString *fullFileName = [NSString stringWithFormat:#"%#/TarefasSalvas.plist", documentsDirectory];
is not the correct way of getting the file path. You should use thestringByAppendingPathComponent: method on documentsDirectory like this,
NSString *fullFileName = [documentsDirectory stringByAppendingPathComponent:#"TarefasSalvas.plist"];
It would also make sense to declare fullFileName as the static variable rather than documentsDirectory.
Thanks #Deepak.
After u giving me the hint about making the Log Alerts on Debugging, I noticed that the iPad is killing the App and then the app can't call the applicationWillTerminate: method as you mentioned before.
So I solved the Problem changing my code to:
- (void)applicationWillTerminate:(NSNotification *)notification{
[self SavingStatus];
}
-(void)SavingStatus {
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:lisTitulos];
[array addObject:lisImagens];
[array addObject:lisData];
[array addObject:lisDetalhes];
[array writeToFile:[self GetApplicationDocumentsDirectory] atomically:YES];
}
As you can see, I created a method that I call on applicationWillTerminate: method and everytime the app reload the Table data:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
...
[self SavingStatus];
return cell;
}
By this way, even if your device Kill the App before it Close normally, the informations will be saved anyway =D.
Thanks again to #Deepak
and everybody who replied me.

Dynamically created UIView Objects

I have a predicament, in as much that I need to create an arbitrary amount of UIView Objects. I have an NSArray and what I need to do is create UIView Objects for the number of items in the array, so I got an int from the [NSArray count]; method, so I know the number of objects needing creating, but the way to implement this has me stumped. I'll include some psudocode below to attempt to give across what I need to do:
[UIView returnMultipleUIViewsForInt:[theArray count]];
Obviously that won't work, but some way of creating an arbitrary amount of objects at runtime, which I can work with would be good.
So in short:
I need to create a certain number of UIViews based upon the number of items in an array.
I then need to access each view that is created and use it as a regularly created view might be used, doing things like adding one of them as a subview to a different view.
- (NSArray *)createNumberOfViews:(NSInteger)number
{
NSMutableArray *viewArray = [NSMutableArray array];
for(NSInteger i = 0; i < number; i++)
{
UIView *view = [[UIView alloc] init];
// any setup you want to do would go here, e.g.:
// view.backgroundColor = [UIColor blueColor];
[viewArray addObject:view];
[view release];
}
return viewArray;
}
NSMutableArray *newViews = [NSMutableArray array];
for (int i=0; i<[theArray count]; ++i) {
UIView *view = [[UIView alloc] init];
[newViews addObject:view];
[view release];
}

Resources