2013-10-25 3 views
-2

JSON을 통해 제품 ID를 구문 분석 한 다음 세부 정보보기로 푸시하고 URL에 넣어 선택한 제품에 대한 자세한 정보를 구문 분석하지만 didSelectRowAtIndexPath은 잘못된 색인 경로를 반환합니다. 제품이로드되지 않은 행 마지막으로 검색된 행의 제품 ID를 가져옵니다.didSelectRowAtIndex에 대한 잘못된 indexPath

예를 들어 5 행이 표시됩니다. 내 논리는 각 행 (행 1, 행 2, 행 3, 행 4, 행 5)에 대해 모든 ID를 올바르게 구문 분석합니다. 행 1에 연결된 정보를 얻고 싶기 때문에 행 1의 정보 대신 상세 뷰가 행 5에 대한 정보를 구문 분석하는 명령을 얻습니다. 왜냐하면 그 행의 마지막 ID가 구문 분석 된 후 표시됩니다. 잘못된 정보.

didSelectRowAtIndexPath 메서드가 올바른 행에 대한 올바른 정보를 얻는 방법을 모르겠다.

여기 didSelectRowAtIndexPath 내 코드입니다 :

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    UIStoryboard *iPhone = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil]; 
    CJArtikelDetailViewController *artikelView = [iPhone instantiateViewControllerWithIdentifier:@"detail"]; 

    NSString *detail = [NSString stringWithFormat:@"%@", wareID]; 

    artikelView.productID = detail; 

    [self.navigationController pushViewController:artikelView animated:YES]; 
    [neuheitenTableView deselectRowAtIndexPath:indexPath animated:YES]; 
    NSLog(@"IndexPath: %@", [indexPath description]); 
} 



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *neuheitenCell = @"neuheitenCell"; 
    CJHomeTableCell *cell = [tableView dequeueReusableCellWithIdentifier:neuheitenCell]; 

    /* 
    NSNumber *preis = [[arrayArtikelPreis objectAtIndex:indexPath.row] objectForKey:@"preis"]; 
    NSMutableString *test = [NSMutableString stringWithFormat:@"€ %@", preis]; 
    cell.artikelPreis.text = test; 
     */ 

    NSString *imageString = [[arrayNeuheiten objectAtIndex:indexPath.row] objectForKey:@"bild"]; 
    //NSLog(@"BildURL: %@", imageString); 
    NSURL *imageURL = [NSURL URLWithString:imageString]; 
    [cell.artikelImage setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@""]]; 

    NSDictionary *object = [arrayNeuheiten objectAtIndex:indexPath.row]; 
    //NSLog(@"%@", object); 

    wareID = [object objectForKey:@"ware_id"]; 
    NSLog(@"Waren ID: %@", wareID); 

    cell.artikelName.text = [object objectForKey:@"name"]; 
    cell.artikelHersteller.text = [object objectForKey:@"lieferant_name"]; 


    return cell; 

} 

나는 방법은 어떻게 든 선택했지만, 난 방법을 모르고 워드 프로세서에 대한 정보를 찾을 수있는 행을 결정해야한다.

미리 도움을 청하십시오!

+0

indexPath.row 당신을 위해 작동하지 않았다 도움이? –

+0

indexPath.row 어디서? –

+0

웨어는 무엇입니까? wareid에 값을 할당 할 코드를 게시 할 수 있습니까 –

답변

1

희망이

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    UIStoryboard *iPhone = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil]; 
    CJArtikelDetailViewController *artikelView = [iPhone instantiateViewControllerWithIdentifier:@"detail"]; 
    NSDictionary *object = [arrayNeuheiten objectAtIndex:indexPath.row]; 
    //NSLog(@"%@", object); 
    //assign selected product id to wareId here and pass it to detail view controller it will work 
    wareID = [object objectForKey:@"ware_id"]; 
    NSLog(@"Waren ID: %@", wareID); 
    NSString *detail = [NSString stringWithFormat:@"%@", wareID]; 

    artikelView.productID = detail; 

    [self.navigationController pushViewController:artikelView animated:YES]; 
    [neuheitenTableView deselectRowAtIndexPath:indexPath animated:YES]; 
    NSLog(@"IndexPath: %@", [indexPath description]); 
} 



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *neuheitenCell = @"neuheitenCell"; 
    CJHomeTableCell *cell = [tableView dequeueReusableCellWithIdentifier:neuheitenCell]; 

    /* 
    NSNumber *preis = [[arrayArtikelPreis objectAtIndex:indexPath.row] objectForKey:@"preis"]; 
    NSMutableString *test = [NSMutableString stringWithFormat:@"€ %@", preis]; 
    cell.artikelPreis.text = test; 
    */ 

    NSString *imageString = [[arrayNeuheiten objectAtIndex:indexPath.row] objectForKey:@"bild"]; 
    //NSLog(@"BildURL: %@", imageString); 
    NSURL *imageURL = [NSURL URLWithString:imageString]; 
    [cell.artikelImage setImageWithURL:imageURL placeholderImage:[UIImage imageNamed:@""]]; 

    //comment out wareId value assigning code here 
    NSDictionary *object = [arrayNeuheiten objectAtIndex:indexPath.row];//commemted this line by mistake 
    //NSLog(@"%@", object); 

    //wareID = [object objectForKey:@"ware_id"]; 
    //NSLog(@"Waren ID: %@", wareID); 

    cell.artikelName.text = [object objectForKey:@"name"]; 
    cell.artikelHersteller.text = [object objectForKey:@"lieferant_name"]; 


    return cell; 

} 
+0

조금 다르게했습니다. 나는 cell.artikelName.text와 cell.artikelHersteller.text에 대한 객체가 더 필요하기 때문에 두 번째 NSDictionary를 추가했습니다. 다른 사용자를위한 코드를 편집하십시오. 나는 그것을하고 싶지 않다 :) 다시 한번 감사드립니다! –

+0

'NSDictionary * object = [arrayNeuheiten objectAtIndex : indexPath.row];'실수로이 행을 주석 처리했습니다. 이제 확인하십시오. –

+0

예. 이 코드는 완벽하게 작동합니다! –

관련 문제