Possible Duplicate:
Images in Uiscroll cell populated by mysql database
-(void)getItems
{
NSString *root = URL
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/phpfile", root]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
{
[self.object removeAllObjects];
id results = [JSON valueForKeyPath:@"ids"];
[results enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop)
{
[self.object addObject:[NSString stringWithFormat:@"%@",[obj valueForKey:@"item1"]]];
[self.object2 addObject:[NSString stringWithFormat:@"%@",[obj valueForKey:@"item2"]]];
-(void)DidLoad
{
//initializing arrays to hold data
//Initiate arrays that hold data
object1 = [[NSMutableArray alloc] init];
object2 = [[NSMutableArray alloc] init];
[getItems];
//Why do I get empty arrays here e.g object 1 and 2 are returning empty ?
Assuming this is your question:
This code:
Is creating new arrays dynamically on the heap. They are naturally empty because they were just brought into existence.
This line:
I think you are trying to call the
getItemsmethod you posted above, but you are not referencing an object in the method call. You want:And even then, you still have a problem; assuming the
getpart of the name is supposed to be getting something (items), you are not returning anything from the method (which is marked with avoidreturn type).