iPhone: соединение не загружается - PullRequest
0 голосов
/ 25 февраля 2012

Я получил правильный URL в методе loaddescriptiondata. Моя проблема заключается в том, что после выполнения URL-адреса выполняется просмотр таблицы, а не загрузка соединения. Почему это происходит?

Это мой код:

Операция разбора.m :

-(void)loadDescriptiondata:(NSString*)itemId{
    isDescription = TRUE;
    [self initilizeData];


    NSString *stringToAppend = @"?method=showMenuItemDesc&res_id=";

    NSString *append2=@"&groupcat=individual&app=iphone";

    NSString *newURLAsString = [NSString stringWithFormat:@"%@%@%@%@",URL,stringToAppend,itemId,append2];

    NSURL *url = [NSURL URLWithString:newURLAsString];

    NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];

    urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];

    NSLog(@"url shop  desp=%@",url);
}

Viewdidload

- (void)viewDidLoad{
    parse = [[ParseOperation alloc]init];
    categoryImageUrl =[[NSMutableArray alloc]init];

    parse.delegate = self;
} 

Mytableview

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"LazyTableCell";

    // add a placeholder cell while waiting on table data

    AsyncImageView *asyncImageView = nil;
    UILabel *label = nil;
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] ;


    } 
    else {
        asyncImageView = (AsyncImageView *) [cell.contentView viewWithTag:ASYNC_IMAGE_TAG];
        label = (UILabel *) [cell.contentView viewWithTag:LABEL_TAG];
    }
    iId=[ids objectAtIndex:indexPath.row];
     NSLog(@".....id... %@",iId);
    [parse loadDescriptiondata:(NSString *)iId];


    NSString *urlString = [categoryImageUrl objectAtIndex:indexPath.row];
    urlString=[urlString stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
    NSURL *url = [NSURL URLWithString:urlString];
    [asyncImageView loadImageFromURL:url];  
} 

Отредактировано

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    [responseData setLength:0];

}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    [responseData appendData:data];

}


#pragma mark -
#pragma mark Process loan data
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    self.responseData = nil;
    NSLog(@"Connected");
    //   NSLog(@"respond string %@",responseString);
    NSArray  *latestLoans = [responseString JSONValue] ;
    categoryData = [[CategoryData alloc] init];
    for(int i=0;i<[latestLoans count];i++)
    {
      NSString* shortTitle13 = [loan objectForKey:@"photourl"];
   spiceType = [loan objectForKey:@"spicinesstype"];

      img =[loan objectForKey:@"photourl"];

       [array2 addObject:shortTitle13];


        if(isDescription == TRUE){

            [spiceTypeArray addObject:spiceType];



               [spiceArrayID addObject:spiceID];

            }

        }

if(isDescription == TRUE){

        [self.delegate didFinishParsingImageUrl:array2];//phot


    }

Ответы [ 2 ]

0 голосов
/ 10 января 2013

после просмотра вашего кода я могу только предположить, что у вас нет сильной связи с вашим свойством urlConnection. То есть "@property (nonatomic, strong) NSURLConnection urlConnection". Немного поздно, но надеюсь, что это поможет другим ..

0 голосов
/ 25 февраля 2012

Я не смотрел на AsyncImageView, но без использования каких-либо внешних платформ я выполнил то, что, по моему мнению, вы пытаетесь выполнить, как описано здесь: http://dbrajkovic.wordpress.com/2012/01/08/load-images-asynchronously-in-a-uitableview-using-gcd-grand-central-dispatch/

Отредактировано Ну, во-первых, давайте поместим некоторую проверку ошибок здесь. Я делаю это каждый раз, когда создаю NSURLConnection:

if (urlConnection) {
    // Create the NSMutableData to hold the received data.
    responseData = [NSMutableData data];
} else {
    // Inform the user that the connection failed.
}
...