how can i use *[10] type?

Discussion in 'iOS Programming' started by junmoney83, Mar 8, 2010.

  1. junmoney83 macrumors newbie

    Joined:
    Mar 3, 2010
    #1
    Code:
    @interface testTable2ViewController : UIViewController 
    {
    	NSMutableArray **indexStore;
    }
    
    @property(nonatomic , retain) NSMutableArray **indexStore;
    
    @end
    
    @implementation testTable2ViewController
    @synthesize indexStore;
    
    - (void)viewDidLoad 
    {
    	NSMutableArray *jung[10];
    
    	for (NSInteger i = 0; i <10; i++)
    	{
    		jung[i] = [[NSMutableArray alloc]init];
    		indexStore[i] = [[NSMutableArray alloc]init];
    	}//for
    }
    
    
    @end
    //////////////////////////////////////////////////////
    jung = [[NSMutableArray alloc]init]; is working good....
    but indexStore = [[NSMutableArray alloc]init]; can't work
    Error Message is EXC_BAD_ACCESS...

    why it is not working?
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    Because indexStore is nil.

    You define the variable in the header. Good.

    You use the contents of the variable in viewDidLoad. Bad.

    You need something that will run before viewDidLoad, which will initialize the testTable2ViewController so it's ready for use. Normally, that's an -init method of some kind.
     
  3. junmoney83 thread starter macrumors newbie

    Joined:
    Mar 3, 2010
    #3
    but this is working...

    jung = [[NSMutableArray alloc]init];
    is working good.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Code:
    NSMutableArray [COLOR="Red"]**[/COLOR]indexStore;
    You sure you want a pointer to a pointer there?
     
  5. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #5


    Because the jung array is declared as an array. You didn't declare indexStore as an array.

    If you want an array, you have to define the variable as an array. For example, if you want indexStore to be an array of 10 NSMutable-pointers, you should use this in your .h file:
    Code:
    NSMutableArray *indexStore[10];
    
    It seems like you don't fully understand the difference between pointer-to-pointer (indexStore, for example) and array-of-pointer (jung, for example).


    If you explain what you're trying to accomplish, then it might be easier to offer advice. All we know is that you're having trouble, but since we don't know what you're trying to do, we can't really offer any specific advice.
     

Share This Page