2013-07-09 4 views
0

전체 C.R.U.D. 응용 프로그램을 원격 데이터베이스에 저장하십시오. 이 질문을 게시 할 때 내 앱이 제대로 작동하고 있습니다. 그러나 나는 그것을 발전시키고 싶다. 나는 IOS 개발의 초보자이다. 내 코드에서 볼 수 있듯이 valueForKey 이름을 가져 와서 tableview에 표시하고 있습니다. 이름을 클릭하면 텍스트 필드에 이름이있는 화면이 나타납니다. 그러나 다음 키에 대한 valueForKey를 얻고 싶습니다 : namesid, address1, address2, address3, address4, email, mobile, telephone 및 comment 그리고 이름을 표시하려면 모든 값이 자신의 텍스트 필드에 표시됩니다.SBJson 데이터 Uitableview에서 NSDictionary 개체를 읽고 표시하는 방법

- (void)requestFinished:(ASIHTTPRequest *)request 
{ 
//Enable the Reload Button. 
self.navigationItem.leftBarButtonItem.enabled = YES; 
//Enable the Add Contact Detail Button. 
self.navigationItem.rightBarButtonItem.enabled = YES; 

searchBar.hidden = NO; 

SBJsonParser *parser = [[SBJsonParser alloc] init]; 

if (request.responseStatusCode == 200) { 

    [self.activityIndicator stopAnimating]; 

    NSString *json_string = [request responseString]; 

    // Actually parsing the JSON 
    NSArray *statuses = [parser objectWithString:json_string error:nil]; 

    for (NSDictionary *status in statuses){ 
     @try { 

      [remotecontacts addObject:[status valueForKey:@"name"]]; 

     } 
     @catch (NSException *exception) { 

      [remotecontacts addObject:[NSString stringWithFormat:@""]]; 

     } 

    } // end for 

    NSDictionary *remotecontactsInDict = [NSDictionary dictionaryWithObject:remotecontacts forKey:@"Contacts"]; 

    [listOfItems addObject:remotecontactsInDict]; 

    [self.myTableViewController reloadData]; 


} else { 

    //Enable the Reload Button. 
    self.navigationItem.leftBarButtonItem.enabled = YES; 
    //Enable the Add Contact Details Button. 
    self.navigationItem.rightBarButtonItem.enabled = YES; 

    //Stop the Activity Indicator. 
    [self.activityIndicator stopAnimating]; 

    UIAlertView *myAlert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Unexpected error, please try again later!"delegate:self cancelButtonTitle:@"Ok"otherButtonTitles:nil]; 
    [myAlert show]; 
    [myAlert release]; 
    return; 
} 


} 

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:  (NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
} 

// Set up the cell... 

if(searching) 
    cell.text = [copyListOfItems objectAtIndex:indexPath.row]; 
else { 

    //First get the dictionary object 
    NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section]; 

    NSArray *array = [dictionary objectForKey:@"Contacts"]; 
    NSString *cellValue = [array objectAtIndex:indexPath.row]; 
    cell.text = cellValue; 

} 

return cell; 

}

// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

if (searching) 
    return [copyListOfItems count]; 
else { 

    //Number of rows it should expect should be based on the section 
    NSDictionary *dictionary = [listOfItems objectAtIndex:section]; 
    NSArray *array = [dictionary objectForKey:@"Contacts"]; 
    return [array count]; 

} 

}

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

//Get the selected country 

NSString *selectedCountry = nil; 

if(searching) 
    selectedCountry = [copyListOfItems objectAtIndex:indexPath.row]; 
else { 

    NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section]; 
    NSArray *array = [dictionary objectForKey:@"Contacts"]; 
    selectedCountry = [array objectAtIndex:indexPath.row]; 
} 

//Initialize the detail view controller and display it. 
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]]; 
dvController.selectedCountry = selectedCountry; 
[self.navigationController pushViewController:dvController animated:YES]; 
[dvController release]; 
dvController = nil; 

}

+0

그래서, 당신의 질문은 무엇입니까 ?? –

답변

0

난 강력하게 당신이 분별있는 TableView 프레임 워크를 체크 아웃 권하고 싶습니다. 프레임 워크는 자동으로 원격 데이터를 가져 와서 테이블보기에 표시합니다. 이 작업을 수동으로 수행하는 것보다 많은 시간을 절약 할 수 있습니다.

+0

예 매트 덕분에. 나는 첫 번째 기지로 적절하게 돌아가서 재 설계하는 것을 의미한다. 나는 당신이 수동으로 말하는이 응용 프로그램을 완료했습니다. 나는 앱을 모두 완벽하게 만들고 아주 잘 작동한다. 단지 몇 가지 코드 샘플을 사용하여 수동으로 추가 정보를 표시하고 다시 표시하는 데 약간의 도움이 필요했습니다. –