“EXC_BAD_ACCESS" signal received - iphone

i am beginner in iphone programming i am doing an app of photo gallery in which while scrolling the UITableView i am getting this exception in my device as Program received signal: “EXC_BAD_ACCESS”
can anyone pls help me tackle this problem...
enter cod[super viewDidLoad];
self.title=#"Back";
udf=[NSUserDefaults standardUserDefaults];
id_arr=[[NSMutableArray alloc]init];
descrip_arr=[[NSMutableArray alloc]init];
path_arr=[[NSMutableArray alloc]init];
count_arr=[[NSMutableArray alloc]init];
client = [[[ClientController alloc] init] autorelease];
r_m = [[[RequestMessage alloc]init] autorelease];
m_j = [[[Main_Json alloc]init] autorelease];
[r_m setServiceType:#"IMAGE"];
[r_m setParameter:#"sample string"];
NSString * json_string = [m_j returnJsonString:r_m:#"button"];
json_string=[json_string stringByAppendingFormat: #"\n"];
NSLog(#"Client is sending:%#", json_string);
//NSLog(json_string);
client.connect;
NSLog(#"client connecting........");
if([client isConnected])
{
NSString *flag = [client send:json_string];
if(![flag isEqualToString:#"success"])
{
NSLog(#"Before Alert_view");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:flag delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
return;
}
NSString *Var=[client receiveResponse];
//NSLog(#"TEST:%#",Var);
NSString *main_str=[Var stringByReplacingOccurrencesOfString:#"!#{}&" withString:#""];
//main_str=[Var stringByReplacingOccurrencesOfString:#"{\"serviceType\":\"ALLIMAGE\",\"parameters\":[[]]}" withString:#""];
NSLog(#"Split:%#",main_str);
js=[[JsontoObject alloc]sivajiTV_response:main_str];
e1=[[Event alloc]init];
NSLog(#"TEST1:%#",[udf objectForKey:#"id_value"]);
NSLog(#"TEST2:%#",[udf objectForKey:#"des_value"]);
NSLog(#"TEST3:%#",[udf objectForKey:#"path_value"]);
NSLog(#"TEST4:%#",[udf objectForKey:#"count_value"]);
id_arr=[[udf objectForKey:#"id_value"] componentsSeparatedByString:#","];
NSArray *descrip_arr1 =[[udf objectForKey:#"des_value"] componentsSeparatedByString:#","];
NSArray *path_arr1=[[udf objectForKey:#"path_value"] componentsSeparatedByString:#","];
count_arr=[[udf objectForKey:#"count_value"] componentsSeparatedByString:#","];
//NSLog(#"-------------");
//NSLog(#"STRING_ID2:%#",descrip_arr1);
//NSLog(#"STRING_ID3:%#",path_arr1);
//NSLog(#"-------------");
for (int i=0; i<[descrip_arr1 count]; i++) {
NSString *temp=[NSString stringWithFormat:#"%#",[descrip_arr1 objectAtIndex:i]];
//NSLog(#"STRING_test:%#",temp);
temp=[temp stringByReplacingOccurrencesOfString:#"\"" withString:#""];
//NSLog(#"STRING_test1:%#",temp);
[descrip_arr addObject:temp];
NSString *temp1=[NSString stringWithFormat:#"%#",[path_arr1 objectAtIndex:i]];
temp1=[temp1 stringByReplacingOccurrencesOfString:#"\"" withString:#""];
[path_arr addObject:temp1];
}
NSLog(#"------------------------------------------------------------------------------");
NSLog(#"STRING_ID1:%#",id_arr);
NSLog(#"STRING_ID2:%#",descrip_arr);
NSLog(#"STRING_ID3:%#",path_arr);
NSLog(#"STRING_ID4:%#",count_arr);
NSLog(#"------------------------------------------------------------------------------");
if([main_str isEqualToString: [NSNull null]])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:main_str delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
return;
}
}
else
{
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:nil message:#"Connection not Found" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert1 show];
[alert1 release];
}
UILabel *lblTitle=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 40)];
lblTitle.backgroundColor=[UIColor clearColor];
self.navigationItem.titleView=lblTitle;
toolbar=[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 25)];
toolbar.barStyle=UIBarStyleBlackOpaque;
[self.view addSubview:toolbar];
UILabel *mylabel = [[UILabel alloc] initWithFrame:CGRectMake(250, 2, 60, 20)];
mylabel.backgroundColor=[UIColor clearColor];
mylabel.textColor = [UIColor whiteColor];
mylabel.text = #"Gallery";
[toolbar addSubview:mylabel];
myTableView.frame=CGRectMake(0,26, 320,430);
// myTableView.backgroundView=nil;
[self.view addSubview:myTableView];
//self.myTableView.separatorColor = [UIColor clearColor];
//UITableViewController *myTableViewController = [[UITableViewController alloc] initWithTableStyle:UITableViewStyleGrouped];
// UIToolBar *myToolBar = [[UIToolBar alloc]initWithFrame:CGRectMake(0, 15, 320, 10)];
// CGRect *toolBarFrame;
// toolBarFrame = CGMakeRect (0, 440, 320, 40);
// [toolBarFrame setFrame:toolBarFrame];
// [myTableViewController.view addSubView:toolBarFrame];
//viewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"movies.jpg"]];
//myTableView.rowHeight=120;
[self.view addSubview:myTableView];
//tempArray = [[NSArray alloc] initWithObjects:#"Sports",#"News",#"naturals1",#"live",nil];
//titleArray = [[NSArray alloc] initWithObjects:#"SA spinners made the difference: Sammy",#"Cabinet terminates ISRO’s deal",#"Hudson River Fish Evolve Toxic ",#"Hi Today Special News?",nil];
//SBJSON *json = [SBJSON new];
// json.humanReadable = YES;
//self.tableDataList = tempArray;
//self.myTableView.backgroundColor = [UIColor clearColor];
//create new uiview with a background image
//UIImage *backgroundImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"movies" ofType:#"jpg"]];
//UIImageView *backgroundView = [[UIImageView alloc] initWithImage:backgroundImage];
//adjust the frame for the case of navigation or tabbars
//backgroundView.frame = CGRectMake(0, 0, 320, 460);
//add background view and send it to the back
//[self.viewController.view addSubview:backgroundView];
//[self.viewController.view sendSubviewToBack:backgroundView];
//[backgroundView release];
//UIImage *img1= [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://122.183.217.134:8080/sivajitv/photos/20101216001017.jpg"]]];
//NSLog(#"ERROR1:%#",img1);
//NSData *imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:#"http://122.183.217.134:8080/sivajitv/photos/20101216001017.jpg"]];
//NSLog(#"ERROR12:%#",imageData);
}

There are so many things wrong with your code it is hard to know where to begin:
client.connect; is syntactic sugar for [client connect], however since connect is not a property (at least I hope it is not a property), you should not use the dot-notation.
The argument to isEqualToString: expects an NSString * object, not NSNull *. If you want to see whether the variable points to a string (as opposed to nil), or, if you want to make sure that the string actually contains characters, use:
if ([main_str length])
// do something
You assign a new mutable array that you own to id_arr using id_arr=[[NSMutableArray alloc]init];, however you completely overwrite this reference later with id_arr=[[udf objectForKey:#"id_value"] componentsSeparatedByString:#","];. This means that the original array that you created (and own) can no longer be referenced, and is leaked.
You never initialise the object that you allocated:
js=[[JsontoObject alloc]sivajiTV_response:main_str];
You create an Event object, but never use it or release it (this is a memory leak):
e1=[[Event alloc]init];

Related

Changing width and height of Alert Message i-Phone

Was wondering what the correct way would be to initialise my alert popup with a smaller window
-(void)alertMessage1:(NSString*) title:(NSString*) message1 {
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:#"Successfully uploaded!" message:message1 delegate:self cancelButtonTitle:#"Okay" otherButtonTitles:nil];
}
You can create a UIAlertview as you suggested like this
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Title Here" message:#"Message here" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
[alert setDelegate:self];
[alert show];
[alert release];
and if you want to adjust the frame them use
- (void)willPresentAlertView:(UIAlertView *)alertView {
alertView.frame = CGRectMake(20.f, 200.f, 280.f, 93.f);
NSArray *subViewArray = alertView.subviews;
for(int x=0;x<[subViewArray count];x++){
if([[[subViewArray objectAtIndex:x] class] isSubclassOfClass:[UILabel class]])
{
UILabel *label = [subViewArray objectAtIndex:x];
label.textAlignment = UITextAlignmentLeft;
}
}
}
In this alertView.frame = CGRectMake(20.f, 200.f, 280.f, 93.f); the CGRectMake(X-position, Y-Position, width, Height). Change it and your work will be done.
You should create custom AlertView or use one of these :
https://www.cocoacontrols.com/search?utf8=%E2%9C%93&q=alertview
For the question you raised in comment changing the background color of UIAlertview you can add the background image like this directly. I am not sure if you can add the color or not.
UIAlertView *theAlert = [[[UIAlertView alloc] initWithTitle:#"Atention" message: #"YOUR MESSAGE HERE", nil) delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] autorelease];
[theAlert show];
UILabel *theTitle = [theAlert valueForKey:#"_titleLabel"];
[theTitle setTextColor:[UIColor redColor]];
UILabel *theBody = [theAlert valueForKey:#"_bodyTextLabel"];
[theBody setTextColor:[UIColor blueColor]];
UIImage *theImage = [UIImage imageNamed:#"Background.png"];
theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16];
CGSize theSize = [theAlert frame].size;
UIGraphicsBeginImageContext(theSize);
[theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];
theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[[theAlert layer] setContents:[theImage CGImage]];

How to add smiley on my alert view? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Image in UIAlertView
I am implementing a puzzle game. after player won I'm showing an alert that You won. but with that I want to add smiley on my alert view. How to do that?
use this
UIAlertView *successAlert = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(220, 10, 40, 40)];
NSString *path = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"smile.png"]];
UIImage *bkgImg = [[UIImage alloc] initWithContentsOfFile:path];
[imageView setImage:bkgImg];
[bkgImg release];
[path release];
[successAlert addSubview:imageView];
[imageView release];
[successAlert show];
[successAlert release];
copied form here

how can I change appearance of alert from UINotification?

is there any way to change the outlook(appearance shape) of UINotification Alert, like I can insert image on UIAlertView, as below
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Status Update" message:myString delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 30, 100, 100)];
NSString *path = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"reminder_logo.png"]];
UIImage *bkgImg = [[UIImage alloc] initWithContentsOfFile:path];
[imageView setImage:bkgImg];
[bkgImg release];
[path release];
[alert addSubview:imageView];
[imageView release];
[alert show];
[alert release];
This code will show an image on UIAlertView. I want same thing for UINotification, but apple should accept it, because I can't alter their libraries, else rejection will happen from app store.
Local notifications are created and displayed by the system, not your app. Therefore you have no control over how they are presented.

iPhone thinks textfields are empty after navigating through views (only on 8C148a)

Hey guys, I have the strangest bug in my application I'm developing.
The thing is I have a login screen with two textfields that I create, add as subviews and release, all done in viewDidLoad.
Then as the user has logged in and logs out again, the textfields appear as normal but when the login-method is called it thinks the textfields are empty!
I have also only found this bug on iOS 4.2.1 (8C148a)
Furthemore the log show "Received memory warning. Level=1" and sometimes "Level=2" and this might be related but I don't know.
Can anyone help me? I'm quite lost...
My viewDidLoad:
userNameTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 85, 280, 30)];
userNameTextField.returnKeyType = UIReturnKeyNext;
userNameTextField.placeholder = #"Användarnamn:";
userNameTextField.layer.cornerRadius = 8;
userNameTextField.alpha = 0.9;
userNameTextField.opaque = YES;
userNameTextField.tag = 0;
userNameTextField.backgroundColor = [UIColor whiteColor];
userNameTextField.textAlignment = UITextAlignmentCenter;
userNameTextField.textAlignment = UIBaselineAdjustmentAlignBaselines;
userNameTextField.borderStyle = UITextBorderStyleRoundedRect;
userNameTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
userNameTextField.adjustsFontSizeToFitWidth = FALSE;
[userNameTextField addTarget:self
action:#selector(textFieldDidReturn:)
forControlEvents:UIControlEventEditingDidEndOnExit];
passwordTextField = [[UITextField alloc] initWithFrame:CGRectMake(20, 119, 280, 30)];
passwordTextField.returnKeyType = UIReturnKeyDone;
passwordTextField.placeholder = #"Lösenord:";
passwordTextField.secureTextEntry = YES;
passwordTextField.layer.cornerRadius = 8;
passwordTextField.alpha = 0.9;
passwordTextField.opaque = NO;
passwordTextField.tag = 1;
passwordTextField.backgroundColor = [UIColor whiteColor];
passwordTextField.textAlignment = UITextAlignmentCenter;
passwordTextField.textAlignment = UIBaselineAdjustmentAlignBaselines;
passwordTextField.borderStyle = UITextBorderStyleRoundedRect;
passwordTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
passwordTextField.adjustsFontSizeToFitWidth = TRUE;
[passwordTextField addTarget:self
action:#selector(textFieldDidReturn:)
forControlEvents:UIControlEventEditingDidEndOnExit];
[self.view addSubview:userNameTextField];
[self.view addSubview:passwordTextField];
userNameTextField.delegate = self;
passwordTextField.delegate = self;
[userNameTextField release];
[passwordTextField release];
I also use the following methods:
-(void) touchesBegan:(NSSet *) touches withEvent:(UIEvent *)event {
[userNameTextField resignFirstResponder];
[passwordTextField resignFirstResponder];
[super touchesBegan:touches withEvent:event ];}
-(IBAction)textFieldDone:(id)sender {
[sender resignFirstResponder];}
-(BOOL)textFieldDidReturn:(UITextField *)textfield {
NSInteger nextTextFieldTag = textfield.tag + 1;
// Find next responding textfield
UIResponder *nextRespondingTextField = [textfield.superview viewWithTag:nextTextFieldTag];
if (nextRespondingTextField) {
[nextRespondingTextField becomeFirstResponder];
} else {
[self logInUser];
[textfield resignFirstResponder];
}
return NO;}
-(IBAction) logInUser {
// Popup alert
if (userNameTextField.text.length == 0 && passwordTextField.text.length == 0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"Vänligen ange användarnamn och lösenord." delegate:nil cancelButtonTitle:#"Stäng." otherButtonTitles:nil];
[alert show];
[alert release];
} else if (passwordTextField.text.length == 0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"Vänligen ange lösenord." delegate:nil cancelButtonTitle:#"Stäng." otherButtonTitles:nil];
[alert show];
[alert release];
} else if (userNameTextField.text.length == 0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"Vänligen ange användarnamn." delegate:nil cancelButtonTitle:#"Stäng." otherButtonTitles:nil];
[alert show];
[alert release];
} else {
PreschoolAppDelegate *globalAppDelegate = [[UIApplication sharedApplication] delegate];
// Set global username and password
globalAppDelegate.globalUserName = #"";
globalAppDelegate.globalPassword = #"";
globalAppDelegate.globalUserName = userNameTextField.text;
globalAppDelegate.globalPassword = passwordTextField.text;
// Clear variables
globalAppDelegate.globalFirstname = [[NSMutableString alloc] init];
globalAppDelegate.globalLastname = [[NSMutableString alloc] init];
globalAppDelegate.globalChildFirstname = [[NSMutableString alloc] init];
globalAppDelegate.globalChildSurname = [[NSMutableString alloc] init];
globalAppDelegate.globalChildFullname = [[NSMutableString alloc] init];
globalAppDelegate.globalSelectedChild = [[NSMutableString alloc] init];
globalAppDelegate.globalIdString = [[NSMutableString alloc] init];
globalAppDelegate.globalChildIdString = [[NSMutableString alloc] init];
globalAppDelegate.globalSelectedChildId = [[NSString alloc] init];
globalAppDelegate.globalWipChildList = [[NSMutableArray alloc] init];
globalAppDelegate.globalChildIdList = [[NSMutableArray alloc] init];
globalAppDelegate.globalChildList = [[NSMutableArray alloc] init];
globalAppDelegate.globalWipChildArray = [[NSMutableArray alloc] init];
globalAppDelegate.tempGlobalAbsenceArray = [[NSMutableArray alloc] init];
globalAppDelegate.tempGlobalChildArray = [[NSMutableArray alloc] init];
globalAppDelegate.globalAbsenceDescription = [[NSMutableArray alloc] init];
globalAppDelegate.globalVacationDescription = [[NSMutableArray alloc] init];
globalAppDelegate.tempGlobalVacationArray = [[NSMutableArray alloc] init];
globalAppDelegate.globalVacationWipChildArray = [[NSMutableArray alloc] init];
globalAppDelegate.globalVacationStartDate = [[NSMutableArray alloc] init];
globalAppDelegate.globalVacationEndDate = [[NSMutableArray alloc] init];
globalAppDelegate.globalVacationStartDates = [[NSMutableArray alloc] init];
globalAppDelegate.globalVacationEndDates = [[NSMutableArray alloc] init];
//
// Start the fetch of the data from the rest service
//
userClient = [[GetUserListRestClient alloc] init];
[userClient getUsers:self];
[pendingLogin startAnimating];
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:#selector (checkIfConnFinished:) userInfo:nil repeats:YES];
}}
I think the problems are in the property assignments like this:
globalAppDelegate.globalFirstname = [[NSMutableString alloc] init];
globalAppDelegate.globalWipChildList = [[NSMutableArray alloc] init];
This way your Strings and Arrays you created are never released. This caused the memory warnings. The good way is this:
NSMutableString *str = [[NSMutableString alloc] init];
globalAppDelegate.globalFirstname = str;
[str release];
Or a shorter but not as good solution:
globalAppDelegate.globalWipChildList = [[[NSMutableArray alloc] init] autorelease];
I hope I could help.

NSScrollView gives error when scrolling "-[CALayer isEqual:]: message sent to deallocated instance"

I'm trying to fix my code but I have no idea why I'm getting these errors:
modifying layer that is being finalized - 0x11818240
2010-09-10 02:35:53.022 iPhone Monkey Curling[1606:207] modifying layer that is being finalized - 0x11818240
2010-09-10 02:35:53.023 iPhone Monkey Curling[1606:207] modifying layer that is being finalized - 0x11818240
2010-09-10 02:35:54.671 iPhone Monkey Curling[1606:207] *** -[CALayer isEqual:]: message sent to deallocated instance 0x11818240
This happens when my all_score_table scroll view has had an attempt to scroll it (Crashes immediately on scroll attempt). Here is my code which sets the scroll views:
NSMutableArray * scores_data = [[first_data componentsSeparatedByString: #"\n"] mutableCopy];
if ([scores_data count] != 3) {
UIAlertView *connection_alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Malformed server response." delegate:nil cancelButtonTitle:#"Close" otherButtonTitles: nil];
[connection_alert show];
[connection_alert release];
return;
}
if([[scores_data objectAtIndex:0] isEqual:#""]){
[scores_data replaceObjectAtIndex:0 withObject:#"No scores for today,"];
}
if([[scores_data objectAtIndex:1] isEqual:#""]){
[scores_data replaceObjectAtIndex:1 withObject:#"No scores this week,"];
}
if([[scores_data objectAtIndex:2] isEqual:#""]){
[scores_data replaceObjectAtIndex:2 withObject:#"No scores,"];
}
[scores_data replaceObjectAtIndex:0 withObject: [[scores_data objectAtIndex:0] componentsSeparatedByString: #";"]];
[scores_data replaceObjectAtIndex:1 withObject: [[scores_data objectAtIndex:1] componentsSeparatedByString: #";"]];
[scores_data replaceObjectAtIndex:2 withObject: [[scores_data objectAtIndex:2] componentsSeparatedByString: #";"]];
NSLog(#"scores_data");
if (todays_scores_table){
//One of the tables exist so all of them must. Release them for renewal.
[todays_scores_table release];
[week_scores_table release];
[all_scores_table release];
[online_scores_pages release]; //release pages also
}
NSLog(#"1");
todays_scores_table = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 110, 295, 300)];
week_scores_table = [[UIScrollView alloc] initWithFrame:CGRectMake(330, 110, 295, 300)];
all_scores_table = [[UIScrollView alloc] initWithFrame:CGRectMake(650, 110, 295, 300)];
todays_scores_table.contentSize = CGSizeMake(205, 60 + 40*[[scores_data objectAtIndex:0] count]);
week_scores_table.contentSize = CGSizeMake(205, 60 + 40*[[scores_data objectAtIndex:1] count]);
all_scores_table.contentSize = CGSizeMake(205, 60 + 40*[[scores_data objectAtIndex:2] count]);
NSLog(#"2");
NSArray * score_data;
NSString * path = [[NSBundle mainBundle] pathForResource: #"single_score_image" ofType:#"png"];
NSData * data = [[NSData alloc] initWithContentsOfFile:path];
UIImage * background_image = [[UIImage alloc] initWithData:data];
UIImageView * background_view;
UIImage * header_image;
if(submission){
path = [[NSBundle mainBundle] pathForResource: #"scores_header" ofType:#"png"];
[data release];
NSLog(#"3");
data = [[NSData alloc] initWithContentsOfFile:path];
header_image = [[UIImage alloc] initWithData:data];
}
UIImageView * header_view;
int offset;
UILabel * label;
NSLog(#"4");
UIScrollView * tables[3] = {todays_scores_table,week_scores_table,all_scores_table};
online_scores_pages = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 420)];
online_scores_pages.contentSize = CGSizeMake(960, 420);
online_scores_pages.pagingEnabled = YES; //Act like iphone home page
UIImage * title_image;
UIImageView * title_view;
NSLog(#"5");
//border for scores table
[data release];
path = [[NSBundle mainBundle] pathForResource: #"score_table_border" ofType:#"png"];
data = [[NSData alloc] initWithContentsOfFile:path];
UIImage * border_image = [[[UIImage alloc] initWithData:data] autorelease];
UIImageView * score_table_border;
for (int a = 0; a < 3; a++) {
if(submission){ //Only do header when submitting score
header_view = [[UIImageView alloc] initWithImage: header_image];
header_view.frame = CGRectMake(10, 10, 275, 30);
NSLog(#"5A");
[tables[a] addSubview: header_view];
[header_view release];
label = [[UILabel alloc] initWithFrame:CGRectMake(25, 10, 245, 30)];
label.backgroundColor = [UIColor clearColor];
NSLog(#"5B");
NSString * end;
NSLog(#"5C");
if ([[scores_data objectAtIndex:a+3] characterAtIndex:0] == '1'){
end = #"st";
}else if ([[scores_data objectAtIndex:a+3] characterAtIndex:0] == '2'){
end = #"nd";
}else if ([[scores_data objectAtIndex:a+3] characterAtIndex:0] == '3'){
end = #"rd";
}else{
end = #"th";
}
NSArray * pos_data = [[scores_data objectAtIndex:a+3] componentsSeparatedByString: #"/"];
label.text = [NSString stringWithFormat: #"You came %#%# from %# scores.",[pos_data objectAtIndex:0],end,[pos_data objectAtIndex:1]];
[tables[a] addSubview:label];
NSLog(#"5E");
[label release];
NSLog(#"6");
}
for (int x = 0; x < [[scores_data objectAtIndex:a] count]; x++){
score_data = [[[scores_data objectAtIndex:a] objectAtIndex:x] componentsSeparatedByString: #","];
//Image for each score
offset = 50 + 40*x;
background_view = [[UIImageView alloc] initWithImage: background_image];
background_view.frame = CGRectMake(10, offset, 275, 30); //Reposition
[tables[a] addSubview: background_view];
[background_view release];
//Add score position
label = [[UILabel alloc] initWithFrame:CGRectMake(10, offset, 30, 30)];
label.backgroundColor = [UIColor clearColor];
label.text = [NSString stringWithFormat: #"%i",x+1];
label.textAlignment = UITextAlignmentCenter;
[tables[a] addSubview:label];
[label release];
NSLog(#"7 %# \n\n %#",score_data,scores_data);
//Add name
label = [[UILabel alloc] initWithFrame:CGRectMake(55, offset, 190, 30)];
label.backgroundColor = [UIColor clearColor];
label.text = [score_data objectAtIndex:0];
[tables[a] addSubview:label];
[label release];
//Add score
label = [[UILabel alloc] initWithFrame:CGRectMake(55, offset, 225, 30)];
label.backgroundColor = [UIColor clearColor];
label.text = [NSString stringWithFormat: #"%#",[score_data objectAtIndex:1]];
label.textAlignment = UITextAlignmentRight;
[tables[a] addSubview:label];
[label release];
NSLog(#"8");
}
//Add title
switch (a) {
case 0:
path = [[NSBundle mainBundle] pathForResource: #"todays_scores_title" ofType:#"png"];
break;
case 1:
path = [[NSBundle mainBundle] pathForResource: #"week_scores_title" ofType:#"png"];
break;
case 2:
path = [[NSBundle mainBundle] pathForResource: #"all_scores_title" ofType:#"png"];
break;
}
[data release];
data = [[NSData alloc] initWithContentsOfFile:path];
title_image = [[[UIImage alloc] initWithData:data] autorelease];
title_view = [[[UIImageView alloc] initWithImage: title_image] autorelease];
title_view.frame = CGRectMake(25 + 320*a, 15, 270, 75); //Reposition and resize
[online_scores_pages addSubview:title_view];
NSLog(#"9");
//Add table
score_table_border = [[UIImageView alloc] initWithImage: border_image];
score_table_border.frame = CGRectMake(320*a, 100, 320, 320); //Reposition
[online_scores_pages addSubview: tables[a]];
[online_scores_pages addSubview: score_table_border];
[score_table_border release];
}
[data release];
if(submission){
[header_image release];
[header_view release];
}
[background_image release];
[background_view release];
[self addSubview: online_scores_pages];
[online_scores_pages becomeFirstResponder];
Thank you for any help. It is much appreciated.
The only iEqual: that I see is in the series of tests:
if([[scores_data objectAtIndex:0] isEqual:#""]){
if([[scores_data objectAtIndex:1] isEqual:#""]){
if([[scores_data objectAtIndex:2] isEqual:#""]){
So looking back at scores_data I see:
MutableArray * scores_data = [[first_data componentsSeparatedByString: #"\n"] mutableCopy];
Is first_data a NSString? If so I'm suspecting that componentsSeparatedByString will return a array of strings. This means that when you do [scores_data objectAtIndex:?] you will get a string.
The isEqual: at this point then looks wrong. Instead of isEqual: you should probably use isEqualToString:.
However, you're seeing a problem with accessing a deallocated object. That implies an excessive number of releases and I can't see that here.
I don't like that call to "mutableCopy" that you are using. I'd prefer to be more explicit in the initialisation:
MutableArray * scores_data = [[NSMutableArray alloc] initWithArray:[first_data componentsSeparatedByString: #"\n"]];
Finally! I found the problem.
I had this call - [background_view release]; once to many. I remove it at the end as it was being released when necessary in the for loop.
Now it works!!!!