开发者

Synthetise an NSMutableArray

      for(int i=0;i<[promotionArr count];i++)
            { 
               // NSLog(@"ok");
                Promotion *prom = [[Promotion alloc]init];
                开发者_C百科prom.pName=[[promotionArr objectAtIndex:i] objectForKey:@"name"];

                prom.pUrl=[[promotionArr objectAtIndex:i] objectForKey:@"url"];
                prom.pDescription=[[promotionArr objectAtIndex:i] objectForKey:@"description"];

                [promMUAraay addObject:prom];
                 NSLog(@"number of elements : %d",[promMUAraay count]);

 }

But the number of element is always 0 . I haven't do @synthetise for the NSMutableArray , xcode tell me that i can't .I just do this in my .h

NSMutableArray *promMUAraay;

It's that the problem ?


Have you remembered to alloc, init the array?

NSMutableArray *array = [[NSMutableArray alloc] init];

Do this before you use the array.


You should initialize your NSArray before accessing it. That is, in your .m file, in your -init method, you should have some code like this:

promMUAraay = [[NSMutableArray alloc] init.......];

For all the options you have initializing an NSArray, see the NSArray reference.

As to your attempt at syntethizing the array, the @synthetize keyword is used to automatically create definitions for setter/getter methods to your array (provided you have a corresponding @property declaration in your interface). This does not change things in that you would all the same need to initialize your NSArray in the init method of your class. The only thing is that you could thereafter refer your variable using the dot-notation: self.promMUAraay.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜