Strongly retained array empty - ios

I have an NSArray that I fill with SKTexture to animate an animal leaping:
#interface PSFrogNode ()
#property (strong, nonatomic) NSArray *leapFrames;
#end
#implementation PSFrogNode {
}
- (instancetype)init
{
self = [super init];
if (self) {
SKTextureAtlas *frogLeapAtlas = [SKTextureAtlas atlasNamed:kFrogLeapAtlas];
int numImages = frogLeapAtlas.textureNames.count;
NSMutableArray *tempArray = [NSMutableArray arrayWithCapacity:numImages];
for (int i=1; i <= numImages/2; i++) {
NSString *textureName = [NSString stringWithFormat:#"frogLeap%d", i];
SKTexture *temp = [frogLeapAtlas textureNamed:textureName];
[tempArray addObject:temp];
}
self.leapFrames = [NSArray arrayWithArray:tempArray];
self = [PSFrogNode spriteNodeWithTexture:[self.leapFrames objectAtIndex:0]];
[self setUserInteractionEnabled:NO];
}
return self;
}
- (void)animateFrogLeap
{
[self runAction:[SKAction animateWithTextures:self.leapFrames timePerFrame:0.09 resize:NO restore:YES]];
}
The array self.leapFrames is allocated in the init method but when the scene calls the animateFrogLeap method it's empty (meaning nil).
Why is that?

You want to create the array outside of the init method and then pass it in:
When creating the view
SKTextureAtlas *frogLeapAtlas = [SKTextureAtlas atlasNamed:kFrogLeapAtlas];
int numImages = frogLeapAtlas.textureNames.count;
NSMutableArray *images = [NSMutableArray arrayWithCapacity:numImages];
for (int i=1; i <= numImages/2; i++) {
NSString *textureName = [NSString stringWithFormat:#"frogLeap%d", i];
SKTexture *temp = [frogLeapAtlas textureNamed:textureName];
[images addObject:temp];
}
PSFrogNode *node = [[PSFrogNode alloc] initWithImages:images];
// Now use the node
PSFrogNode.h
-(instancetype)initWithImages:(NSArray *)images;
PSFrogNode.m
#interface PSFrogNode ()
#property (nonatomic, copy) NSArray *leapFrames;
#end
#implementation PSFrogNode
-(instancetype)initWithImages:(NSArray *)images
{
self = [self initWithTexture:[images firstObject]];
if (self) {
_leapFrames = [images copy];
[self setUserInteractionEnabled:NO];
}
return self;
}
As mentioned in my comment, the below line in your original implementation would mean that self would be reassigned, so the line before it (assigning the array to the property) would then be meaning less.
self = [PSFrogNode spriteNodeWithTexture:[self.leapFrames objectAtIndex:0]];

Related

can't add the Dynamic values in Pie Carts [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 6 years ago.
Improve this question
//
// PieChartTest.m
// Yazaki
//
// Created by apple on 3/25/16.
// Copyright (c) 2016 apple. All rights reserved.
//
#import "PieChartTest.h"
#import "testingvc.h"
#interface PieChartTest ()
#property (strong, nonatomic) NSMutableArray *values;
#property (strong, nonatomic) NSMutableArray *testARYY;
#property (strong, nonatomic) NSMutableArray *labels;
#property (strong, nonatomic) NSMutableArray *colors;
#property (nonatomic) BOOL inserting;
#property (strong, nonatomic) NSArray *colors1;
#property (strong, nonatomic) NSDictionary *serviceResponse;
#property(strong,nonatomic) NSString *item;
#property(strong,nonatomic) NSArray *temp;
#property (strong, nonatomic) NSDictionary *sample;
#end
#implementation PieChartTest
#synthesize dictObject;
#synthesize str1;
#synthesize str2;
- (void)viewDidLoad {
[super viewDidLoad];
NSString *baseURL = [NSString stringWithFormat:#"http://192.168.1.122:8099/YazakiService.svc/SESSION/%#/%#/%#",dictObject,str1,str2];
NSURL *url = [NSURL URLWithString:[baseURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLResponse *response;
NSError *error;
NSData *responseData =[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
_serviceResponse=[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];
NSArray *temp = [_serviceResponse objectForKey:#"SESSIONCOUNT"];
NSDictionary *sample=[temp objectAtIndex:0];
NSString*item=[sample objectForKey:#"COUNTVALUE"];
if( [_serviceResponse objectForKey:#"SESSIONCOUNT"] == nil ||
[[_serviceResponse objectForKey:#"SESSIONCOUNT"] isEqual:[NSNull null]] ){
// do nothing
}else
{
NSArray *temp = [_serviceResponse objectForKey:#"SESSIONCOUNT"];
if ([temp isKindOfClass:[NSArray class]] && temp.count !=0)
{
// value is available
[self.values removeAllObjects];
self.values = [NSMutableArray new];
int i;
for (i=0; i<[temp count]; i++) {
[self.values addObject:[NSString stringWithFormat:#"%#",[[temp objectAtIndex:i] objectForKey:#"COUNTVALUE"]]];
[self.values addObject:[NSString stringWithFormat:#"%#",[[temp objectAtIndex:i] objectForKey:#"SESSIONVALUE"]]];
}
}
}
self.pieChartView.dataSource = self;
self.pieChartView.delegate = self;
self.pieChartView.animationDuration = 0.5;
self.pieChartView.sliceColor = [MCUtil flatWetAsphaltColor];
self.pieChartView.borderColor = [MCUtil flatSunFlowerColor];
self.pieChartView.selectedSliceColor = [MCUtil flatSunFlowerColor];
self.pieChartView.textColor = [MCUtil flatSunFlowerColor];
self.pieChartView.selectedTextColor = [MCUtil flatWetAsphaltColor];
self.pieChartView.borderPercentage = 0.01;
}
- (NSInteger)numberOfSlicesInPieChartView:(MCPieChartView *)pieChartView {
return self.values.count;
}
- (CGFloat)pieChartView:(MCPieChartView *)pieChartView valueForSliceAtIndex:(NSInteger)index {
return [[self.values objectAtIndex:index] floatValue];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)pieChartView:(MCPieChartView*)pieChartView didSelectSliceAtIndex:(NSInteger)index;
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
testingvc *destViewController = (testingvc*)[storyboard instantiateViewControllerWithIdentifier:#"testing"];
self.values = [_serviceResponse objectForKey:#"SESSIONCOUNT"];
// //destViewController = [CategoryVC.destViewController objectAtIndex:0];
NSDictionary *sample=[self.values objectAtIndex:index];
NSString*item=[sample objectForKey:#"SESSIONVALUE"];
//
destViewController.category = item;
destViewController.STATUS =dictObject;
destViewController.fromDate=str1;
destViewController.Todate=str2;
[destViewController setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:destViewController animated:NO completion:nil];
}
#end
i got the error while select the 4th slice index ...i got the crash of
2016-03-31 11:40:10.582 Yazaki[2150:37777] * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayM objectAtIndex:]: index 4 beyond bounds [0 .. 3]'
*** First throw call stack:
change this
self.values=[_serviceResponse objectForKey:#"SESSIONCOUNT"];
NSLog(#"got response==%#", self.values);
int i;
for (i=0; i<[self.values count]; i++) {
NSDictionary *exp=[self.values objectAtIndex:i];
_item=[exp objectForKey:#"COUNTVALUE"];
//[self.testARYY addObject:item];
}
[self.values addObject:_item];
into and try
NSArray *temp = [_serviceResponse objectForKey:#"SESSIONCOUNT"];
if (temp.count>0)
{
[self.values removeAllObjects];
self.values = [NSMutableArray new];
for (i=0; i<[temp count]; i++) {
[self.values addObject:[NSString Stringwithformat:#"%#",[[temp objectAtIndex:i] objectForKey:#"COUNTVALUE"]]];
}
}
or use like
Choice-2
NSArray *temp = [_serviceResponse objectForKey:#"SESSIONCOUNT"];
if ([temp isKindOfClass:[NSArray class]] && temp.count !=0)
{
// value is available
[self.values removeAllObjects];
self.values = [NSMutableArray new];
for (i=0; i<[temp count]; i++) {
[self.values addObject:[NSString Stringwithformat:#"%#",[[temp objectAtIndex:i] objectForKey:#"COUNTVALUE"]]];
}
}
Update-2
if( [_serviceResponse objectForKey:#"SESSIONCOUNT"] == nil ||
[[_serviceResponse objectForKey:#"SESSIONCOUNT"] isEqual:[NSNull null]] ){
// do nothing
}else
{
NSArray *temp = [_serviceResponse objectForKey:#"SESSIONCOUNT"];
if ([temp isKindOfClass:[NSArray class]] && temp.count !=0)
{
// value is available
[self.values removeAllObjects];
self.values = [NSMutableArray new];
for (i=0; i<[temp count]; i++) {
[self.values addObject:[NSString Stringwithformat:#"%#",[[temp objectAtIndex:i] objectForKey:#"COUNTVALUE"]]];
}
}
}
You should try to change this line:
return [[self.values objectAtIndex:index] floatValue];
to this
return [[self.values objectAtIndex:index][#"COUNTVALUE"] floatValue];
The error says that you are trying to call the floatValue function on a NSMutableDictionary, from my understanding you should call it on the value stored under the "COUNTVALUE" key of the dictionary.

Call out of an Array, objectAtIndex

I have an Array with 10 Objects. I take the first Object and put it into my Label with a String.
Then I want to have a Method that increases the objectAtIndex by 1.
This is my Code :
//.m
#interface GameViewController () {
NSInteger _labelIndex;
}
#property (nonatomic) NSArray *playerArray;
#property (nonatomic) NSString *playerLabel;
- (void)viewDidLoad {
[super viewDidLoad];
self.playerArray = [NSArray arrayWithObjects:#"FIRST", #"SECOND", #"THIRD", #"FOURTH", #"FIFTH", #"SIXT", #"SEVENTH", #"EIGTH", #"NINTH", #"TENTH", nil];
_labelIndex = 0;
[self updateTurnLabel];
self.turnLabel.text = [NSString stringWithFormat:#"YOUR %# DRAW?", self.playerLabel];
}
Here I call the Method i another Method:
-(void) flipDraws {
self.boardView.userInteractionEnabled = NO;
[self updateTurnLabel];
CardView *cv1 = (CardView *) self.turnedDrawViews[0];
CardView *cv2 = (CardView *) self.turnedDrawViews[1];
}
This is my Method:
-(void) updateTurnLabel {
self.playerLabel = [self.playerArray objectAtIndex:_labelIndex % self.playerArray.count]; _labelIndex++;
}
I tried it with a for Loop but nothing happened. I tried it with just set the objectAtIndex:1 but my Method was not called.
What I am doing wrong?
{
int a;
}
- (void)viewDidLoad {
[super viewDidLoad];
a = 0;
self.playerArray = [NSArray arrayWithObjects:#"FIRST", #"SECOND", #"THIRD", #"FOURTH", #"FIFTH", #"SIXT", #"SEVENTH", #"EIGTH", #"NINTH", #"TENTH", nil];
self.playerLabel = [self.playerArray objectAtIndex:a];
self.turnLabel.text = [NSString stringWithFormat:#"YOUR %# DRAW?", self.playerLabel];
}
-(void) updateTurnLabel {
a +=1;
if (!a<[playerArray count])
{
a = 0;
}
self.playerLabel = [self.playerArray objectAtIndex:a];
}
call self.turnLabel.text = [NSString stringWithFormat:#"YOUR %# DRAW?", self.playerLabel]; after [self updateTurnLabel];
What are you adding +1 to in the method objectAtIndex:.
You should be maintaining a variable which tracks the current index being used, then in your method use this :
-(void) updateTurnLabel {
self.playerLabel = [self.playerArray objectAtIndex:currentIndex+1];
}

iOS(Objective-C). Application crash when getting block from array

Have a question about blocks in objective-c.
For example I have a list of actions.
I'm initializing an array of blocks:
self.actions = #[
^() { [self showObject:self.object_1]; },
^() { [self showObject:self.object_2]; },
^() { [self showObject:self.object_3]; }
];
And calling them when some row is pressed:
- (void)pressedRowAtIndex:(NSInteger)index {
if (index < actions.count) {
void (^action)() = [actions objectAtIndex:index];
if (action != nil) {
action();
}
}
}
And all works fine without problem. But when I init my actions array by using initWithObjects method:
self.actions = [NSArray alloc] initWithObjects:
^() { [self showObject:self.object_1]; },
^() { [self showObject:self.object_2]; },
^() { [self showObject:self.object_3]; },
nil
];
Than I get crash trying to get action by index by using objectAtIndex method of NSArray class.
I understand the difference between this inits. First one don't increase reference count like first do. But can someone explain why it crash?
Edit:
All that I've found. Maybe I'm nub and somewhere else is another useful information.
There is no crash info in terminal:
Code for Onik IV:
Small example:
#interface ViewController () {
NSArray *actions;
}
#property (nonatomic, strong) NSString *object1;
#property (nonatomic, strong) NSString *object2;
#property (nonatomic, strong) NSString *object3;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
actions = [[NSArray alloc] initWithObjects:
^() { [self showObject:self.object1];},
^() { [self showObject:self.object2]; },
^() {[self showObject:self.object3]; },
nil];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.object1 = #"object 1";
self.object2 = #"object 2";
self.object3 = #"object 3";
void(^firsSimpleBlock)(void) = [actions lastObject];
firsSimpleBlock();
void(^simpleBlock)(void) = [actions firstObject];
simpleBlock();
}
-(void)showObject:(NSString *)object
{
NSLog(#"Show: %#",object);
}
#end
Try something like this.
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
(^someBlock)(void) = ^void(void){
self.object1;
};
actions = [[NSArray alloc] initWithObjects:
[someBlock copy],
[someOtherBlock copy],
[anotherBlock copy],
nil];
}
Blocks are allocated on the stack and are therefor removed when the frame is removed from the stack leading to sail pointers for all pointers pointing to that block. When you allocate a object with the literal "#" sign the object is allocated in a pool so all literals that are the "same" point to the same instance and are never deallocated.
NSString *a = #"A";
NSString *b = #"A";
points to the same instance of a string, while:
NSString *a = [NSString stringWithFormat:#"A"];
NSString *b = [NSString stringWithFormat:#"A"];
are two different objects.
So it works when you are creating a literal array but when you add the blocks dynamically they will be removed when its time to use them therefor the BAD_ACCESS. Solution is to send "copy" message to the block that will copy it to the heap and the block will not be released.
It´s the same, you must have another kind of problem (sintax?).
Try this:
#interface ViewController ()
#property (nonatomic, strong) NSString *object1;
#property (nonatomic, strong) NSString *object2;
#property (nonatomic, strong) NSString *object3;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.object1 = #"object 1";
self.object2 = #"object 2";
self.object3 = #"object 3";
NSArray *actions = #[^() { [self showObject:self.object1];},
^() { [self showObject:self.object2]; },
^() {[self showObject:self.object3]; }
];
NSArray *secondActions = [[NSArray alloc] initWithObjects:
^() { [self showObject:self.object1];},
^() { [self showObject:self.object2]; },
^() { [self showObject:self.object3];},
nil
];
void(^firsSimpleBlock)(void) = [actions lastObject];
firsSimpleBlock();
void(^simpleBlock)(void) = [secondActions firstObject];
simpleBlock();
}
-(void)showObject:(NSString *)object
{
NSLog(#"Show: %#",object);
}
#end

Loading array from folder of images - xcode

I am having some trouble loading images from a file into an array. I have used a combination of questions I have found on here, and am out of ideas.... I am new to objective-c and rusty on the rest.
My viewDidLoad simply calls my showPics method, and for testing sake I have the _imgView just show the image at position 1 in the array.
It could very well be a problem with the way I am showing the images as well. I have a ViewController and one ImageView (titled: imgView) in my Storyboard.
here is my showPics method:
-(void)showPics
{
NSArray *PhotoArray = [[NSBundle mainBundle] pathsForResourcesOfType:#"jpg" inDirectory:#"Otter_Images"];
NSMutableArray *imgQueue = [[NSMutableArray alloc] initWithCapacity:PhotoArray.count];
for (NSString* path in PhotoArray)
{
[imgQueue addObject:[UIImage imageWithContentsOfFile:path]];
}
UIImage *currentPic = _imgView.image;
int i = -1;
if (currentPic != nil && [PhotoArray containsObject:currentPic]) {
i = [PhotoArray indexOfObject:currentPic];
}
i++;
if(i < PhotoArray.count)
_imgView.image= [PhotoArray objectAtIndex:1];
}
Here is my viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self showPics];
}
Here is my ViewController.h
#interface ViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIImageView *imgView;
#end
Please let me know if you need anything else and thank you in advance!
In your showPics method, other than the initial 'for-loop', all of your references to PhotoArray should instead be references to imgQueue. PhotoArray is a list of pathnames. imgQueue is the array of actual UIImage objects.
-(void)showPics {
NSArray *PhotoArray = [[NSBundle mainBundle] pathsForResourcesOfType:#"jpg" inDirectory:#"Otter_Images"];
NSMutableArray *imgQueue = [[NSMutableArray alloc] initWithCapacity:PhotoArray.count];
for (NSString* path in PhotoArray) {
[imgQueue addObject:[UIImage imageWithContentsOfFile:path]];
}
UIImage *currentPic = _imgView.image;
int i = -1;
if (currentPic != nil && [imgQueue containsObject:currentPic]) {
i = [imgQueue indexOfObject:currentPic];
}
i++;
if(i < imgQueue.count) {
_imgView.image = [imgQueue objectAtIndex:1];
}
}

objects in nsmutablearray becoming zombies

i am developing very simple quiz app
In viewDidLoad i am adding objects in myarray
where ever i nslog myarray values it works fine
but if i try this inside ibaction methods all objects becomes zombie
for 2 days i am stuck in this but can't find it what is wrong.
quiz.h
#import <UIKit/UIKit.h>
#import <sqlite3.h>
#class dbVals;
#class viewTransition;
#class AppDelegate;
#interface quiz : UIViewController
{
NSMutableArray *myarray;
IBOutlet UITextView *questionTextView_;
IBOutlet UIButton *skipButton_;
IBOutlet UIButton *optionAButton_;
IBOutlet UIButton *optionBButton_;
IBOutlet UIButton *optionCButton_;
NSString *correctAnswer;
int questionNumber;
int score;
IBOutlet UILabel *scoreLabel_;
int totalQuestions;
}
-(void)populate:(int)number;
//#property(nonatomic, retain) NSMutableArray *myarray;
#property (retain, nonatomic) IBOutlet UITextView *questionTextView;
#property (retain, nonatomic) IBOutlet UIButton *skipButton;
#property (retain, nonatomic) IBOutlet UIButton *optionAButton;
#property (retain, nonatomic) IBOutlet UIButton *optionBButton;
#property (retain, nonatomic) IBOutlet UIButton *optionCButton;
#property (retain, nonatomic) IBOutlet UILabel *scoreLabel;
- (IBAction)optionsToAnswer:(id)sender;
- (IBAction)zzz:(id)sender;
#end
quiz.m
#import "quiz.h"
#import "DbVals.h"
#import "viewTransition.h"
#import "AppDelegate.h"
#implementation quiz
#synthesize skipButton=skipButton_;
#synthesize optionAButton=optionAButton_;
#synthesize optionBButton=optionBButton_;
#synthesize optionCButton=optionCButton_;
#synthesize scoreLabel=scoreLabel_;
#synthesize questionTextView=questionTextView_;
//#synthesize myarray;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)createEditableCopyOfDatabaseIfNeeded
{
//NSLog(#"Creating editable copy of database");
// First, test for existence.
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:#"oq.sqlite"];
success = [fileManager fileExistsAtPath:writableDBPath];
if (success) return;
// The writable database does not exist, so copy the default to the appropriate location.
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"oq.sqlite"];
success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];
if (!success) {
NSAssert1(0, #"Failed to create writable database file with message '%#'.", [error localizedDescription]);
}
}
+(sqlite3 *) getNewDBConnection
{
sqlite3 *newDBconnection;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:#"oq.sqlite"];
// Open the database. The database was prepared outside the application.
if (sqlite3_open([path UTF8String], &newDBconnection) == SQLITE_OK) {
//NSLog(#"Database Successfully Opened ");
} else {
NSLog(#"Error in opening database ");
}
return newDBconnection;
}
- (void)viewDidLoad
{
[super viewDidLoad];
questionNumber = 0;
score = 0;
[self createEditableCopyOfDatabaseIfNeeded];
sqlite3 *dbc = [quiz getNewDBConnection];
sqlite3_stmt *statement = nil;
const char *sqlSelect = "select * from QnA ORDER BY RANDOM()";
if(sqlite3_prepare_v2(dbc, sqlSelect, -1, &statement, NULL)!=SQLITE_OK)
{
NSAssert1(0, #"Error Preparing Statement", sqlite3_errmsg(dbc));
}
else
{
myarray = [[NSMutableArray alloc]init];
while(sqlite3_step(statement)==SQLITE_ROW)
{
NSString *q = [NSString stringWithUTF8String:(char *) sqlite3_column_text(statement, 0)];
NSString *o = [NSString stringWithUTF8String:(char *) sqlite3_column_text(statement, 1)];
NSString *a = [NSString stringWithUTF8String:(char *) sqlite3_column_text(statement, 2)];
DbVals *dbValsObj = [[DbVals alloc]init];
[dbValsObj setValsOfQuestions:q options:o answer:a];
[myarray addObject:dbValsObj];
[dbValsObj release];
}
}
sqlite3_finalize(statement);
//[self populate:questionNumber];
}
-(void)populate:(int)number
{
/*[scoreLabel_ setText:[NSString stringWithFormat:#"%d",score]];
AppDelegate *appDel = [[UIApplication sharedApplication] delegate];
[appDel setFinalScore:[NSString stringWithFormat:#"%d",score]];
if(number < [myarray count])
{
DbVals *dbv1 = [myarray objectAtIndex:number];
[questionTextView_ setText:[dbv1 getQuestions]];
NSString *joinedOptions = [dbv1 getOptions];
NSArray *splitOptions = [joinedOptions componentsSeparatedByString:#","];
[optionAButton_ setTitle:[splitOptions objectAtIndex:0] forState:UIControlStateNormal];
[optionBButton_ setTitle:[splitOptions objectAtIndex:1] forState:UIControlStateNormal];
[optionCButton_ setTitle:[splitOptions objectAtIndex:2] forState:UIControlStateNormal];
correctAnswer = [dbv1 getAnswer];
}
else
{
//viewTransition *vt = [[viewTransition alloc]init];
[viewTransition viewsTransitionCurrentView:self toNextView:#"result"];
//[vt release];
}*/
}
- (void)viewDidUnload
{
for(int i=0; i<[myarray count]; i++)
{
DbVals *dbv1 = [myarray objectAtIndex:i];
NSLog(#"%#",[dbv1 getQuestions]);
NSLog(#"%#",[dbv1 getOptions]);
NSLog(#"%#",[dbv1 getAnswer]);
NSLog(#"<u><u><u><u><><><><><><><><><><><>");
}
[self setQuestionTextView:nil];
[questionTextView_ release];
questionTextView_ = nil;
[self setQuestionTextView:nil];
[skipButton_ release];
skipButton_ = nil;
[self setSkipButton:nil];
[optionAButton_ release];
optionAButton_ = nil;
[self setOptionAButton:nil];
[optionBButton_ release];
optionBButton_ = nil;
[self setOptionBButton:nil];
[optionCButton_ release];
optionCButton_ = nil;
[self setOptionCButton:nil];
[scoreLabel_ release];
scoreLabel_ = nil;
[self setScoreLabel:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc
{
for(int i=0; i<[myarray count]; i++)
{
DbVals *dbv1 = [myarray objectAtIndex:i];
NSLog(#"%#",[dbv1 getQuestions]);
NSLog(#"%#",[dbv1 getOptions]);
NSLog(#"%#",[dbv1 getAnswer]);
NSLog(#"<d><d><d><d><d><><><><><><><><><><>");
}
[questionTextView_ release];
[skipButton_ release];
[optionAButton_ release];
[optionBButton_ release];
[optionCButton_ release];
[scoreLabel_ release];
[myarray release];
[super dealloc];
}
- (IBAction)optionsToAnswer:(id)sender
{
for(int i=0; i<[myarray count]; i++)
{
DbVals *dbv1 = [myarray objectAtIndex:i];
NSLog(#"%#",[dbv1 getQuestions]);
NSLog(#"%#",[dbv1 getOptions]);
NSLog(#"%#",[dbv1 getAnswer]);
NSLog(#"six");
}
if(sender == skipButton_)
{
//questionNumber++;
//[self populate:questionNumber];
/*[UIView animateWithDuration:5 delay:0 options: UIViewAnimationCurveEaseOut
animations:
^{
[UIView setAnimationTransition:103 forView:self.view cache:NO];
}
completion:
^(BOOL finished)
{
}
];*/
}
if(sender == optionAButton_)
{
/*NSString *one = #"1";
if([correctAnswer isEqualToString:one])
{
score++;
}
questionNumber++;
[self populate:questionNumber];*/
}
if(sender == optionBButton_)
{
/*NSString *two = #"2";
if([correctAnswer isEqualToString:two])
{
score++;
}
questionNumber++;
[self populate:questionNumber];*/
}
if(sender == optionCButton_)
{
/*NSString *three = #"3";
if([correctAnswer isEqualToString:three])
{
score++;
}
questionNumber++;
[self populate:questionNumber];*/
}
}
- (IBAction)zzz:(id)sender
{
}
#end
dbVals.h
#import <Foundation/Foundation.h>
#interface DbVals : NSObject
{
NSString *questions_;
NSString *options_;
NSString *answer_;
// NSString *hint;
// NSString *mode;
}
-(void)setValsOfQuestions:(NSString*)questions options:(NSString*)options answer:(NSString*)answer;
-(NSString*)getQuestions;
-(NSString*)getOptions;
-(NSString*)getAnswer;
dbVals.m
#import "DbVals.h"
#implementation DbVals
-(void)setValsOfQuestions:(NSString*)questions options:(NSString*)options answer:(NSString*)answer
{
questions_ = questions;
options_ = options;
answer_ = answer;
}
-(NSString*)getQuestions
{
return questions_;
}
-(NSString*)getOptions
{
return options_;
}
-(NSString*)getAnswer
{
return answer_;
}
#end
Your dbVals.m setVals isn't retaining the parameters. This obviously means, everything inside becomes deallocated once the function scope ends.
Try changing it to something like
-(void)setValsOfQuestions:(NSString*)questions options:(NSString*)options answer:(NSString*)answer
{
[questions_ release];
[options_ release];
[answer_ release];
questions_ = [questions copy];
options_ = [options copy];
answer_ = [answer copy];
}

Resources