Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have declared an array in a header file like this.

NSMutableArray *myArray;

And I have allocated the array in the implementation file loadview method like this.

myArray=[[NSMutableArray alloc]init]; 

And then i have added some data to it from the sqlite database into the array in the same loadview method. The array retains the content only within the loadview method when i try to access it in other methods it throws an error stating that the array is empty.I tried NSlog within the loadview after loading the array with some data. It works fine within loadview method. Why it s not retaining outside the loadview method ? Can anyone please help me out of this ?

NSString *myStr = [myArray objectAtIndex:0];
share|improve this question
1  
Please show us more of your code. It's hard to interpret this. Is the array an instance variable? Are you accessing it from the same instance of your class? –  jtbandes Jun 23 '11 at 5:55
    
@jtbandes I have declared it in the header file of a viewcontroller and then trying to access it from the implementation file. I didnt declare it as a property. –  booleanBoy Jun 23 '11 at 5:59
    
What other methods are you accessing it from? Can you show some of the code? –  jtbandes Jun 23 '11 at 6:00
    
@jtbandes I am trying to access it from a user defined method using the above show code... –  booleanBoy Jun 23 '11 at 6:16
3  
Sorry, this still isn't enough information. You need to show us your code or we can't really help. –  jtbandes Jun 23 '11 at 6:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.