2012-06-02 6 views
0

가능한 중복 :
Images in Uiscroll cell populated by mysql database빈 Nsmutable 배열 아이폰

-(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 ? 
+2

여기에 게시 할 때 더 명확한 질문을하십시오. –

+0

@MichaelDautermann, 같은 코드, 다른 질문입니다. 나는 부분 응답을 가지고 있기 때문에 두 번 게시했습니다. – user1430825

+0

@ShaggyFrog .. 빠른 응답을 주셔서 감사합니다.이 가변 배열 objec1 및 object2 객체 (URL 문자열 객체)가 있습니다. 객체 1에는 사진과 객체의 이름이 있습니다. 2 사진의 URL이 있습니다. 나는이 세부 사항, 예를 들면 사진의 이름을 얻고 싶었다. 하지만 여기에 NSMutable 배열이 반환됩니다.이 명확한가요? – user1430825

답변

1

가정이 질문입니다 :

//Why do I get empty arrays here e.g object 1 and 2 are returning empty ? 

이 코드 :

//Initiate arrays that hold data 
object1 = [[NSMutableArray alloc] init]; 
object2 = [[NSMutableArray alloc] init]; 

힙에 동적으로 새 배열을 만드는 중입니다. 그들은 단지 존재하게 되었기 때문에 그들은 자연스럽게 비어 있습니다.

이 줄 :

[getItems]; 

나는 당신이 위의 게시 된 getItems 메소드를 호출하려고 생각하지만, 당신은 메서드 호출에서 개체를 참조하지 않습니다. 원하는 항목 :

[self getItems]; 

그리고 여전히 문제가 있습니다. 이름의 get 부분이 무언가 (항목)를 가져 오는 것으로 가정하면 (void 반환 유형으로 표시된) 메서드에서 아무 것도 반환하지 않습니다.