Currently developing my first Native iPhone application, the application is going to be integrating within an existing .net application and will be using webServices. However the problem i am facing i believe is nothing more than my understanding of xcode.
I hope i can explain this…
OK within my first view, within the viewDidLoad i go off to the webservice and return my list of items (these populate the tableview) this works completely fine:
— snippet —
- (void)viewDidLoad {
//GET ALL ITEMS
myArray = [[NSMutableArray alloc] init];
MyWebService *webService = [[MyWebService alloc] init];
myArray = [webService getAllNewsFunction];
[super viewDidLoad];
}
— snippet —
Ok so i now have my tableview populated and awaiting for you to select your item (in this case a news article) i need to determine the selectedItem in order to populate the next view with the details of the article. However it appears that within the didSelectRowAtIndexPath method my array list is no longer accessible. I am very confused at this point due to if i simply create a list of items within my viewDidLoad within the current view without using my webservice for example:
— snippet —
// listOfItems = [[NSMutableArray alloc] init];
// [myArray addObject:@"Iceland"];
// [listOfItems addObject:@"Greenland"];
// [listOfItems addObject:@"Switzerland"];
// [listOfItems addObject:@"Norway"];
// [listOfItems addObject:@"New Zealand"];
// [listOfItems addObject:@"Greece"];
// [listOfItems addObject:@"Italy"];
// [listOfItems addObject:@"Ireland"];
— snippet —
the above is accessible within didSelectRowAtIndexPath and i can populate the detailview.
Can you please help me pinpoint the problem i am facing and how this can be solved. I understand i have given you the very basics so if i need to provide more information i am happy to do so.
— update —
ok based on your response i have update the following.
I have now declared myArray as a property
@property (nonatomic, retain) NSMutableArray *myArray;
and also updated the line to:
self.myArray = [webService getAllNewsFunction];
— update —
however i now receive an error “program received signal: “SIGABRT”” on the self.myArray line.
any ideas?
Thanks Again
If you are following naming conventions then the method
[webService getAllNewsFunction]will return an autoreleased array. Therefore when you come to access it again it will most likely have been released already.If you have used a
@propertyto declaremyArray(which you should to save yourself from these problems) then you can resolve this by doing:This line:
is also superflous and causing a memory leak as you are reassigning the value of
myArrayto[webService getAllNewsFunction]immediately after without releasing the newNSMutableArrayyou alloc/init’dUPDATE
So from reading your update I think you need to firstly look at the warnings your project now has which will probably read something like:
The next clue to the problem appears in the console I get something like this
So what it all boils down to is you either need to provide the methods
or let the compiler do it for you by adding a
@synthesizestatement like thisThe synthesize is the easier, quicker options and the compiler will arrange for the coorect memory management depending on which options you use in your
@propertydeclaration.