Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6147723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:09:13+00:00 2026-05-23T19:09:13+00:00

Bear with me on this one. I have an iphone application. It is a

  • 0

Bear with me on this one.

I have an iphone application. It is a questionnaire application. There are several types of question, some have a slider, some have text input etc. I have developed a view controller for each type of question.

Two example types of question controllers are: TextInputQuestionViewController and SliderQuestionViewController.

I have a rootViewcontroller named QuestionnaireViewController. This is defined as follows:

#import <UIKit/UIKit.h>
#import "JSONKit.h";
#import "dbConnector.h"
#import "SliderQuestionViewController.h";
#import "TextInputQuestionViewController.h";
#import "MainMenuProtocol.h";

@interface QuestionnaireViewController : UIViewController {
    NSDictionary* questions;
    NSMutableArray* questionArray;
    NSMutableArray* answerArray;
    dbConnector* db;
    SliderQuestionViewController* currQ; //need to create a generic var
    TextInputQuestionViewController* currQ;
    NSInteger currQNum; 
    NSString* qaTitle;
    NSString* secId;
    id<MainMenuProtocol>delegate;
}

@property(nonatomic, retain) NSDictionary* questions;   
@property(nonatomic, retain) NSMutableArray* questionArray;
@property(nonatomic, retain) NSMutableArray* answerArray;
@property(nonatomic, retain) dbConnector* db;
@property(nonatomic, retain) SliderQuestionViewController* currQ;
@property(nonatomic, retain) TextInputQuestionViewController* currTI;
@property(nonatomic) NSInteger currQNum;
@property(nonatomic, retain) NSString* qaTitle;
@property(nonatomic, retain) NSString* secId;
@property(nonatomic, retain) id <MainMenuProtocol> delegate;

-(void) setQuestions;
-(void) startQuestion:(NSInteger)index isLast:(BOOL)last;
-(void) loadQuestions;
-(void) initialise;
-(void) finishQuestionnaire:(id)sender;
-(void) switchViews:(id)sender;


@end



#import "QuestionnaireViewController.h"
#import "dbConnector.h"
#import "ASIHTTPRequest.h"
#import "JSONKit.h";
#import "Answer.h";


@implementation QuestionnaireViewController
@synthesize questions, questionArray, db, currQ, currQNum, answerArray, qaTitle, secId, delegate;

-(void)viewDidLoad{
    [self initialise];
    answerArray = [[NSMutableArray alloc]init];
    [super viewDidLoad];
    self.title = qaTitle; //set to whatever section is
}

-(void) initialise {
    currQNum = 0;
    [self loadQuestions];
    UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Start" style:UIBarButtonItemStylePlain target:self action:@selector(switchViews:)];          
    self.navigationItem.rightBarButtonItem = anotherButton;
}

-(void) loadQuestions {
    db = [[dbConnector alloc]init];
    //code to initialise view
    [db getQuestions:secId from:@"http://dev.speechlink.co.uk/David/get_questions.php" respondToDelegate:self]; 
}

//called when questions finished loading
//stores dictionary of questions
- (void)requestFinished:(ASIHTTPRequest *)request
{
    NSData *responseData = [request responseData];
    NSString *json = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    NSDictionary *qs = [json objectFromJSONString]; 
    self.questions = qs;
    [json release]; 
    [qs release];
    [self setQuestions];
}


//assigns JSON to question objects
-(void) setQuestions {
    questionArray = [[NSMutableArray alloc] init];
    for (NSDictionary *q in self.questions) {               
        /* Create Question object and populate it */
        id question;
        if([[q objectForKey:@"type"] isEqualToString:@"Slider"]){
            question = [[SliderQuestionViewController alloc]init];  
            //set min max values
        }else if([[q objectForKey:@"type"] isEqualToString:@"Option"]){

        }else if([[q objectForKey:@"type"] isEqualToString:@"TextInput"]){
            question = [[TextInputQuestionViewController alloc]init];
        }else if([[q objectForKey:@"type"] isEqualToString:@"ImagePicker"]){

        }else{
            //comments

        }
        //if else to create appropriate view controller - NEED to identify question type

        [question setQuestionId:[q objectForKey:@"questionId"] withTitle:[q objectForKey:@"question"] number:[q objectForKey:@"questionNumber"] section:[q objectForKey:@"sectionId"] questionType: [q objectForKey:@"type"]];
        /* Add it to question (mutable) array */
        [questionArray addObject:question]; 
        [question release];
    }
}

-(void) startQuestion:(NSInteger)index isLast:(BOOL)last{
    //currQ = [[QuestionViewController alloc]init];
    currQ = [questionArray objectAtIndex:index];
    //push currQ onto navigationcontroller stack
    [self.navigationController pushViewController:currQ animated:YES];
    [currQ addButton:self isLast: last];
}

//pushes new view onto navigation controller stack
-(void) switchViews:(id)sender{ 
    Answer* ans = currQ.question.answer;
    ans.questionId = currQ.question.qId;
    ans.entryId = @"1";//temporary;
    if(currQNum < [questionArray count] - 1){       
        if(currQNum > 0){           
            //if else for different input types
            NSString* qt = currQ.question.qType;
            if([qt isEqualToString:@"Slider"]){
                ans.answer = currQ.sliderLabel.text;
            }else if([qt isEqualToString:@"Option"]){               

            }else if([qt isEqualToString:@"TextInput"]){
                //NSLog(@"%@", currQ.inputAnswer);
                ans.answer = currQ.inputAnswer.text;
            }else if([qt isEqualToString:@"ImagePicker"]){

            }else{

            }                       
            [answerArray addObject: ans];
            [ans release];
        }
        [self startQuestion:currQNum isLast:FALSE];     
        currQNum++;
    }else{
        ans.answer = currQ.sliderLabel.text;
        [answerArray addObject: ans];

        //store data temporarily - section finished     
        [self startQuestion:currQNum isLast:TRUE];              
        currQNum++;
    }
    [ans release];
}

-(void) finishQuestionnaire:(id)sender{
    //go back to main manual
    //if else statement for answers
    NSString* answ = currQ.sliderLabel.text;
    [answerArray addObject: answ];
    [delegate finishedSection:answerArray section:secId];
    [answ release];
    [self.navigationController popToRootViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.questions = nil;
    self.currQ = nil;
    [super viewDidUnload];
}

//hide back button in navigation bar
- (void) viewWillAppear:(BOOL)animated{
    self.navigationItem.hidesBackButton = YES;
}

- (void)dealloc {
    [currQ release];
    [db release];
    [questionArray release];
    [questions release];
    [super dealloc];
}

@end

the problematic lines with the above are in the switchViews function. I need to make the answer equal to the specific input component in that question view (slider value, text input value). So I need to make currQ a type that can be instantiated using any view controller.

I therefore need a generic variable to hold the current question. currQ holds the current question, but at the moment is of type SliderQuestionViewController. I tried to change this to id, but it throws a load of “Request For member…not a structure of union” and also a load of misassigned pointer issues.

Let me know if you need more code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:09:14+00:00Added an answer on May 23, 2026 at 7:09 pm

    This reads like you want a pointer for a UIViewController, so just use that as the type. Then you can cast it down to whatever subclass you like later. For example:

    -(void)myAction:(UIViewController *)vc {
        SpecialViewController *svc = (SpecialViewController *)vc;
        ...
    }
    

    In your case, declare

    UIViewController* currQ;
    

    and then cast it as needed in the implementation to access the different properties and methods of your two subclasses.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im still pretty new so bear with me on this one, my question(s) are
This is a long text. Please bear with me. Boiled down, the question is:
Bit confused with this one so bear with me... I have a Navigation-based project
This is a tough question to word...so bear with me. I have two tables
This is the first question I have asked here so bear with me .
So, i have mIRC making a listen (bear with me on this one) on
I have to do this programmatically. So, bear with me. I have text and
This question is hard to explain so please bear with me. I have a
This might sound like a strange question, but bear with me... I have a
Bear with me if this is unclear; I have trouble fully wrapping my head

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.