2014-09-02 2 views
0

나는 아주 새롭게 iPhone에있다. XIB를 iPhone 용으로 만 사용하는 퀴즈 종류의 앱을 개발 중입니다. 내 문제는 아래에 첨부 된 퀴즈 질문의 n 번호에 대한 사용자 인터페이스 디자인을 만들 필요가있다. 누구든지 이걸 만들 수있는 가장 좋은 방법이 무엇인지 제안 해 주시겠습니까? 백엔드 서버에서 모든 질문과 옵션을 얻고 있습니다. JSON 모델에서 언급 한 모든 퀴즈 질문에 대해 고유 한 ID를 test_id로 사용하고 있습니다. 테이블 뷰 섹션 (질문 텍스트의 경우)과 각 섹션의 네 행 (옵션)을 사용하여 가능하지만 문제는 테스트 ID 1의 경우 옵션 B를 선택하고 테스트 ID 10의 경우 옵션 A를 대답으로 선택한 다음 문제가되는 것입니다. 제출 버튼을 탭하기 전에 선택한 사용자의 대답 옵션 B와 옵션 A를 어떻게 얻을 수 있습니까? 같은 제안을 해주십시오. 사전에iOS에서 퀴즈 모듈 용 사용자 인터페이스를 만드는 방법은 무엇입니까?

{ 
    "test_details": [ 
     { 
      "test_id": 1, 
      "test_qus": "which of the following allows the HP ENVY Beats All-in-One PC to swiftly switch between applications?", 
      "test_ans_optionA": "Quad-Core 1.0 GHz processor", 
      "test_ans_optionB": "Windows® 8.1 OS", 
      "test_ans_optionC": "Intel® Haswell Core Processor", 
      "test_ans_optionD": "Windows 7 OS", 
      "test_correct_ans": "optionA" 
     }, 
     { 
      "test_id": 2, 
      "test_qus": "which of the following makes HP ENVY Beats All-in-One PC the best PC for Beats All-in-One PC the best PC for", 
      "test_ans_optionA": "SRS Premium sound", 
      "test_ans_optionB": "Monster Beats Solo headphones", 
      "test_ans_optionC": "Beats AudioTM quad speakers and quad", 
      "test_ans_optionD": "Windows 7 OS", 
      "test_correct_ans": "optionB" 
     } 
] 
} 

enter image description here

감사 :

여기서 퀴즈 모듈 내 JSON 모델입니다!

+1

가있는 tableview을 가지고 질문에 대한 섹션을의 모든 부분에 대해 수행 답 4 줄. 내가 더 잘 작동하는 것 같아 –

+0

+1 tableview –

+0

고마워 @ SRNayak .. 나는 똑같은 노력하고 있는데, 문제는 어떻게 내가 마지막으로 모든 테이블 행에 대한 사용자의 선택한 대답을 얻을 수 있습니까? pls help me – user2786

답변

0

동적 인 경우 스토리 보드 테이블에서 컨텐츠로 "동적 프로토 타입"을 준비하고 X가 필요한 셀의 수 (테이블 행) 인 프로토 타입 셀의 X를 준비해야합니다 (예 : 스크린 샷 2, 1. 질문 세포, 2. 라디오 버튼 셀)

다음)은 각각 하나의 선택을 radioGroup에 대해 (복수 선택을 유지하기 위해 필요로하는 당신은 라디오 버튼과 추가 문제가있는 것 UITableViewDelegate 및 UITableViewDataSource

를 구현합니다.

//will hold source of the table (data model) that will be maintained 
NSMutableArray *dataSource;//of NSMutableDictionary objects 

#pragma mark - UITableViewDelegate 
-(void)   textView:(UITableView *)tableView 
    didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSMutableDictionary * cellData = dataSource[indexPath.row]; 
    if(cellData) { 
     //here maintain selection state and reload table data e.g. cellData can store "selected" property 
    } else { 
     //error no data for cell at this index 
    } 
} 

테이블

#pragma mark - UITableViewDataSource 
-(NSInteger)tableView:(UITableView *)tableView 
numberOfRowsInSection:(NSInteger)section { 
    return [dataSource count]; 
} 
-(UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSMutableDictionary *cellData = dataSource[indexPath.row]; 
    NSString *cellId = nil; 
    NSInteger type = [[cellData valueForKey:@"type"] integerValue];//datasource can store type that will indicate which cell to display (integer is used so switch can be used) 
    switch (type) { 
     case 0: 
      //header cell 
      cellId = @"headerCell";//this is the cell identifier set in storyboard 
     break; 
     case 1: 
     default: 
      //radiobutton row - default 
      cellId = @"radioButtonCell"; 
     break; 
    } 
    MyCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId 
                 forIndexPath:indexPath]; 
    [cell setData:cellData];//MyCustomCell implements the setData method 

    return cell; 
} 

의 소스와 다음 선택 사용을 업데이트하려면 기본적으로 그게

+0

늦은 답변을 위해 Lukasz, Sry에게 감사드립니다. 저는 XIB와 협력하고 있습니다. XIB를 사용하여 사용자가 선택한 옵션 질문을 현명하게 얻으려면 어떻게해야합니까? – user2786

+0

질문을 더 자세히 업데이트 할 수 있습니까? 당신은 데이터 등으로 그것을 채우고 어떻게 구현합니까? 행마다 dataSource 사전에 그룹 ID가 포함되어 있습니다. 그 이유는 방사선 그룹당 단일 선택을 유지할 수 있기 때문입니다 (데이터 소스를 탐색하고 해당 radiogroup ID를 비교하여 해당 항목의 "selected"상태 만 수정합니다). –

+0

@Lukasz 업데이트 된 질문을 확인하십시오. 내 문제에 대한 설명이 있으면 알려 주시기 바랍니다. – user2786

관련 문제