Objective C의 didFinishLoading에서 IndexPath.row를 얻는 방법 (how to get IndexPath.row in didFinishLoading in Objective C)


문제 설명

Objective C의 didFinishLoading에서 IndexPath.row를 얻는 방법 (how to get IndexPath.row in didFinishLoading in Objective C)

저는 iOS를 처음 사용하고 있으며, didFinishLoading에서 cellforrowAtIndexPath 메서드 외부에서 IndexPath.row를 가져오는 것과 관련된 문제에 직면하고 있습니다. 내 코드는 다음과 같습니다.

6
 ‑ (void)connectionDidFinishLoading:(NSURLConnection *)connection{
    loginStatus = [[NSString alloc] initWithBytes: [myNSMDataFromServer mutableBytes] length:[myNSMDataFromServer length] encoding:NSUTF8StringEncoding];
    NSLog(@"loginStatus =%@",loginStatus);
    NSError *parseError = nil;
    NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLString:loginStatus error:&parseError];
    NSLog(@"JSON DICTIONARY = %@",xmlDictionary);
    recordResult = [xmlDictionary[@"success"] integerValue];
    NSLog(@"Success: %ld",(long)recordResult);
    NSDictionary* Address=[xmlDictionary objectForKey:@"soap:Envelope"];
    NSLog(@"Address Dict = %@",Address);
    NSDictionary *new =[Address objectForKey:@"soap:Body"];
    NSLog(@"NEW DICT =%@",new);
    NSDictionary *LoginResponse=[new objectForKey:@"TFMComplaints_GetNewResponse"];
    NSLog(@"Login Response DICT =%@",LoginResponse);
    NSDictionary *LoginResult=[LoginResponse objectForKey:@"TFMComplaints_GetNewResult"];
    NSLog(@"Login Result =%@",LoginResult);
    if(LoginResult.count>0)
    {
        NSLog(@"Login Result = %@",LoginResult);
        NSLog(@"Login Result Dict =%@",LoginResult);
         NSString *teststr =[[NSString alloc] init];
        teststr =[LoginResult objectForKey:@"text"];
        NSLog(@"Test String Value =%@",teststr);
        NSString *string = [LoginResult valueForKey:@"text"];
        NSLog(@"Now String is =%@",string);
        NSData *data =[string dataUsingEncoding:NSUTF8StringEncoding];
        NSError* error;
        NSArray *array = [NSJSONSerialization JSONObjectWithData:data options:NSUTF8StringEncoding error:&error];
        NSIndexPath *selectedIndexPath = [closetbl indexPathForSelectedRow];
        NSDictionary *firstObj = [array objectAtIndex:selectedIndexPath.row];

        idarray=[[NSMutableArray alloc]init];

        idarray=[firstObj valueForKey:@"Key"];
        NSLog(@"Result Array =%@",idarray);
}

0에 있는 값이 하나만 있습니다.

미리 감사합니다!


참조 솔루션

방법 1:

Just add a for loop for array:

for (int i = 0; i < array.count; i++)
{
    //where i will be the index path. You can use it like this 
    NSDictionary *firstObj = [array objectAtIndex:i];

}

In your case you can use it like this:

idarray=[[NSMutableArray alloc]init];

for (int i = 0; i < array.count; i++){
    NSDictionary *firstObj = [array objectAtIndex:i];
    [idarray addObject:[firstObj valueForKey:@"Key"]];
    NSLog(@"Result Array =%@",idarray);

  }

방법 2:

NSIndexPath *selectedIndexPath = [tableView indexPathForSelectedRow];

For more details follow: https://developer.apple.com/reference/uikit/uitableview/1615000‑indexpathforselectedrow

Hope this helps.

방법 3:

You can use below code to get the indexpath and from this indexpath you can get also the selected cell.

let indexPath = self.tblObj.indexPathForSelectedRow!

let currentCell = self.tblObj.cellForRowAtIndexPath(indexPath)! as! YourTableViewCell

(by MujuUser511MrunalSarabjit Singh)

참조 문서

  1. how to get IndexPath.row in didFinishLoading in Objective C (CC BY‑SA 2.5/3.0/4.0)

#XCode #nsdictionary #objective-c #nsarray #iOS






관련 질문

xcode를 사용하여 OSX 화면 보호기로 플래시 파일 (Flash file as OSX screensaver using xcode)

ARC를 사용하여 VM:ImageIO_GIF_Data를 릴리스하는 방법은 무엇입니까? (How to release VM:ImageIO_GIF_Data using ARC?)

탐색 컨트롤러로 보기로 돌아가기 위해 자동 제스처를 끄는 방법은 무엇입니까? (How to turn off the automatic gesture to go back a view with a navigation controller?)

레코드 삭제 중 오류 발생, 포착되지 않은 예외 'NSInternalInconsistencyException'으로 인해 앱 종료 (error while deleting records,Terminating app due to uncaught exception 'NSInternalInconsistencyException')

xcode 7 시뮬레이터 또는 장치에서 앱을 실행하는 방법은 무엇입니까? (how to run app on xcode 7 simulator or device?)

언래핑 라인을 잡고 잡으시겠습니까? 스위프트 2.0, XCode 7 (Try and catch around unwrapping line? Swift 2.0, XCode 7)

MKMapView 폐색이 주석을 제거합니까? (Does MKMapView occlusion cull it's annotations?)

Objective C의 didFinishLoading에서 IndexPath.row를 얻는 방법 (how to get IndexPath.row in didFinishLoading in Objective C)

xcode의 맵킷에 있는 재설정 버튼 및 책갈피 버튼 (A Reset button and a bookmark button in mapkit in xcode)

Swift 패키지 관리자: 소프트웨어 업데이트 후 정적 빌드 실패 (Swift Package manager : static build failing after software updates)

문서화 오류 Jazzy "0% 문서화되지 않은 기호가 포함된 문서 적용 범위" (documenting error Jazzy "0% documentation coverage with 0 undocumented symbols")

Swift 5에서 Subscript의 모호한 사용? (Ambiguous use of Subscript in Swift 5?)







코멘트