2014-04-18 1 views
0

웹 사이트에서 JSON 파일을 다운로드하고 테이블보기로 표시하는 코드가 있습니다. 다음 단계는 detaillist에 제목 (사람 이름)을 표시하는 것입니다.JSON IOS detailview

어떻게하면됩니까? 기본 화면에 표시되는 데이터를 가져올 수 없습니다.

첫 번째 화면에 이름을 표시하는 코드입니다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath 
(NSIndexPath *)indexPath 
{ 
NSString *cellIdentifier = @"BasicCell"; 
    UITableViewCell *myCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
    // Get the location to be shown 
    Location *item = _feedItems[indexPath.row]; 

// Get references to labels of cell 
myCell.textLabel.text = item.Name; 

    return myCell; 
} 

--- 편집 -----

을 시작 나는 HomeModel.M 클래스에있는 NSDictionary를 얻었다.

for (int i = 0; i < jsonArray.count; i++) 
{ 
    NSDictionary *jsonElement = jsonArray[i]; 

    // Create a new location object and set its props to JsonElement properties 
    Location *newLocation = [[Location alloc] init]; 
    newLocation.Name = jsonElement[@"Email"]; 
    newLocation.list = jsonElement[@"lijst"]; 
    newLocation.Password = jsonElement[@"Password"]; 

    // Add this question to the locations array 
    [_locations addObject:newLocation]; 
} 

// Ready to notify delegate that data is ready and pass back items 
if (self.delegate) 
{ 
    [self.delegate itemsDownloaded:_locations]; 
} 

--- END 편집 ----이 같은 그래서 기본적으로 내가 같은 이름을 표시하는 ToGetList 클래스 입니다 원하는

...

뭔가 :

- (void)viewDidLoad 
    { 
     [super viewDidLoad]; 
     self.nameLabel.text = item.Name //Reference to the ViewController.m class; 
     // Do any additional setup after loading the view. 
    } 
+0

당신이 선택한 셀의 데이터를 표시 하시겠습니까 자기 이름 라벨? – YaBoiSandeep

+0

당신이하고 싶은 것은 NSDictionary를 만들고 JSON 요청 내에서 "keywords"를 찾는 것입니다. 그런 다음 해당 키워드로 사전에 myCell.textLabel.text의 텍스트를 설정하십시오. – user2277872

+0

@ 샌디. 그래, 그게 내가하고 싶은 일이다. 그러나 내가 선택한 셀의 세부 사항을 보여주고 싶다. 예를 들어 내가 John Doe를 선택했다면 detailview에 들어간다. name = John Doe, Occupation = Shoplifter. Mary Doe, 나는 name = Mary Doe, occupation = Housewife를 얻는다. – brian

답변

0

이름, 직업 등의 셀 구성 요소가 포함 된 모델을 만듭니다. JSON의 모든 데이터를 배열로 저장합니다.

self.timeSheetModel = [self.timeSheetListArray objectAtIndex:indexPath.row]; 

당신의 detailVC에서

- (void)tableView:(UITableView *)tableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

self.detailVC = [[DetailVC alloc]init]; 

//Create a property model in your detailVC assign it. 

self.detailVC.model = [self.timeSheetListArray objectAtIndex:indexPath.row]; 

//Pass the model . You will get the data in your detailVC of the selected cell. 

[self.navigationController pushViewController:self.detailVC animated:YES]; 

} 

에서 방법
- (UITableViewCell *)tableView:(UITableView *)tableView 
    cellForRowAtIndexPath:(NSIndexPath *)indexPath 

에서는 값에 액세스 할 수 있습니다 직접

self.myNameLabel.text = self.model.name;