Objective-C: properties not being saved or passed
Posted
by Gerald Yeo
on Stack Overflow
See other posts from Stack Overflow
or by Gerald Yeo
Published on 2010-05-08T16:58:40Z
Indexed on
2010/05/08
17:08 UTC
Read the original article
Hit count: 376
iphone
|objective-c
Hi, i'm a newbie to iphone development. I'm doing a navigation-based app, and I'm having trouble passing values to a new view.
@interface RootViewController : UITableViewController {
NSString *imgurl;
NSMutableArray *galleryArray;
}
@property (nonatomic, retain) NSString *imgurl;
@property (nonatomic, retain) NSMutableArray *galleryArray;
- (void)showAll;
@end
#import "RootViewController.h"
#import "ScrollView.h"
#import "Model.h"
#import "JSON/JSON.h"
@implementation RootViewController
@synthesize galleryArray, imgurl;
- (void)viewDidLoad {
UIBarButtonItem *showButton = [[[UIBarButtonItem alloc]
initWithTitle:NSLocalizedString(@"Show All", @"")
style:UIBarButtonItemStyleBordered
target:self
action:@selector(showAll)] autorelease];
self.navigationItem.rightBarButtonItem = showButton;
NSString *jsonString = [[Model sharedInstance] jsonFromURLString:@"http://www.ddbstaging.com/gerald/gallery.php"];
NSDictionary *resultDictionary = [jsonString JSONValue];
if (resultDictionary == nil) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Webservice Down"
message:@"The webservice you are accessing is currently down. Please try again later."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
else {
galleryArray = [[NSMutableArray alloc] init];
galleryArray = [resultDictionary valueForKey:@"gallery"];
imgurl = (NSString *)[galleryArray objectAtIndex:0];
NSLog(@" -> %@", galleryArray);
NSLog(imgurl);
}
}
- (void)showAll {
NSLog(@" -> %@", galleryArray);
NSLog(imgurl);
ScrollView *controller = [[ScrollView alloc] initWithJSON:galleryArray];
[self.navigationController pushViewController:controller animated:YES];
}
The RootViewController startup and the json data loads up fine. I can see it from the first console trace. However, once I click on the Show All button, the app crashes. It doesn't even trace the galleryArray and imgurl properyly.
Maybe additional pairs of eyes can spot my mistakes. Any help is greatly appreciated!
[Session started at 2010-05-08 16:16:07 +0800.]
2010-05-08 16:16:07.242 Photos[5892:20b] -> (
)
GNU gdb 6.3.50-20050815 (Apple version gdb-967) (Tue Jul 14 02:11:58 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 5892.
(gdb)
© Stack Overflow or respective owner