게시하기 전에 거의 모든 것을 시도했습니다 (Google, Apple Dev Doc 등). 게시하기 전에 아무 것도 놓치지 않았 으면 좋겠다.UITableView iOS 용 NSArray 데이터 소스로 복잡한 JSON
나는 이미 JSON < -> Webservice < -> iPhone 로그인을 구축했다.
NSString *responseString = [[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]autorelease];
NSDictionary *jsonDict = [responseString JSONValue];
NSString *loginResult = [jsonDict valueForKey:@"LoginResult"];
loginResult는 직원의 이름입니다 : 다음 코드로
예를 들어, "벵거 헤닝"
는 해당 JSON은 다음과 같습니다
{"LoginResult":"S:00000412"}
지금은이 더 복잡한 작업을 통해 나는 방법을 찾아 낼 수 없다 :
나는 웹 서비스에서 다음 JSON을 받고 :
NSDictionary *jsonDict = [responseString JSONValue];
NSArray *teamStatus = [jsonDict objectForKey:@"GetTeamPresentStatusResult"];
[self BuildDataSource: nil :teamStatus];
teamStatus 지금 10 키/값 쌍을 포함
는{"GetTeamPresentStatusResult"[
{"Firstname":"Steffen","Id":"00000456","IsPresent":"true","Lastname":"Polker"},
{"Firstname":"Erich","Id":"00000455","IsPresent":"true","Lastname":"Welter"},
{"Firstname":"Titus","Id":"00000454","IsPresent":"true","Lastname":"Sommerbeck"}, {"Firstname":"Ruediger","Id":"00000453","IsPresent":"true","Lastname":"Oelmann"},{"Firstname":"Heinz","Id":"00000452","IsPresent":"true","Lastname":"Radelfs"},{"Firstname":"Franz","Id":"00000451","IsPresent":"true","Lastname":"Wippermann"},{"Firstname":"Klaus-Dieter","Id":"00000450","IsPresent":"true","Lastname":"Just"},{"Firstname":"Alan","Id":"00000412","IsPresent":"true","Lastname":"Turing"},{"Firstname":"Konrad","Id":"00000138","IsPresent":"true","Lastname":"Zuse"},{"Firstname":"Marius","Id":"00000112","IsPresent":"true","Lastname":"Sandmann"}]}
이 처리를위한 내 코드로 시작합니다. 여기
내가 내 테이블에 대한 데이터 소스를 구축하려고하는 방법이다 :
- (void)BuildDataSource: (id) sender: (NSArray*)teamStatusData{
teamStatusMutableArray = [[NSMutableArray alloc]init];
teamStatusDataSection = [[NSArray alloc]initWithArray:teamStatusData];
teamStatusDictSectionOne = [NSDictionary dictionaryWithObject:teamStatusDataSection forKey:@"OrgUnits"];
[teamStatusMutableArray addObject:teamStatusDictSectionOne];
[tblView reloadData];
}
내가 그것을 필요로하는지 데이터를 얻기 위해 여기에서 이동하는 방법을 알아낼 관리 할 수 없습니다.
첫 번째/값이 포함 된 다른 배열과 성/값이 포함 된 다른 배열이 필요합니까? 그렇다면 어떻게해야합니까? 여기
는 I've 지금까지 도움이되지 않았다 시도 몇 줄 수 있습니다- (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...
//First get the dictionary object
NSDictionary *dictionary = [teamStatusMutableArray objectAtIndex:indexPath.section];
NSString *testString = [dictionary valueForKey:@"Firstname"];
NSArray *testarray = [dictionary objectForKey:@"OrgUnits"];
NSString *test = [testarray JSONRepresentation];
test = [test stringByReplacingOccurrencesOfString:@"[" withString:@""];
test = [test stringByReplacingOccurrencesOfString:@"]" withString:@""];
NSDictionary *jsonDict = [test JSONValue];
}
나는 테이블에 결합 할 수있는 직원 이름과 데이터 소스를 가지고있다 필요한 것은. 거기에서 나는 추가 도움없이 내 길을 나아갈 수 있다고 생각합니다.
저는 .NET (C#) 세계에서 왔고 어쩌면 혼란 스럽습니다. 당신은 자세한 문의하시기 바랍니다 필요한 경우
은 .. 당신에게
헤닝
을 너무 많이 주셔서 감사합니다! SPtail에 대한
세부 사항 :
이#import <UIKit/UIKit.h>
#import "RootViewController.h"
#import "EmployeeDetails.h"
@interface OrgUnitAA:NSObject {
NSString *FirstName;
NSString *Id;
NSString *IsPresent;
NSString *LastName;
}
@property (nonatomic, retain) NSString *FirstName;
@property (nonatomic, retain) NSString *Id;
@property (nonatomic, retain) NSString *IsPresent;
@property (nonatomic, retain) NSString *LastName;
@end
@interface TeamStatusView : UIViewController {
UITableView *tblView;
NSMutableArray *teamStatusMutableArray;
NSArray *teamStatusDataSection;
NSDictionary *teamStatusDictSectionOne;
UIViewController *EmployeeDetails;
UIViewController *RootViewController;
NSMutableData *responseData;
}
@property (nonatomic, retain) IBOutlet UITableView *tblView;
@property (nonatomic, retain) NSArray *teamStatusMutableArray;
@property (nonatomic, retain) NSMutableArray *dummyMutableArrayTimeQuota;
@property (nonatomic, retain) NSArray *teamStatusDataSection;
@property (nonatomic, retain) NSDictionary *teamStatusDictSectionOne;
@property (nonatomic, retain) IBOutlet UIViewController *RootViewController;
@property (nonatomic, retain) IBOutlet UIViewController *EmployeeDetails;
- (void)GetTeamStatus: id;
- (void)BuildDataSource: id: (NSArray*)teamStatusData;
@end
안녕하세요 SPatil, 답변 주셔서 감사! OrgUnit * unit = [[OrgUnit alloc] init]을 초기화 할 때 다음과 같은 오류가 발생했습니다. 아키텍처 i386에 대해 정의되지 않은 기호 : 에서 참조 된 "_OBJC_CLASS _ $ _ OrgUnit"TeamStatusView.o의 objc-class-ref ld : 아키텍처 i386에 대한 기호가 없습니다. 나는 봤지만 솔루션을 찾을 coudnt. 내 질문에 위의 .h 파일 내용을 게시합니다. –
클래스 이름이 OrgUnitAA이므로 OrgUnit이 그 오류를 줄 것이며, 내가 바보가되는지 알려줍니다! 그렇지 않으면 OrgUnit에 다른 .h 및 .m을 사용하려고 시도하십시오. – SPatil