Question

i would like to implement a simple survey within my app like in the following screenshot:

Survey app sample screenshot

There is a label with a title, a text view with the question to be asked and a segmented control to give the vote. I want the user read the question, give his vote so the next button (on the top right) will be enabled, and so he could go to the next screen with the next question.

The problem is that i didnt figure out clearly how to implement this. Should I use a scroll view with a page control? or separated view controllers? or something else?

Thanks everyone

Was it helpful?

Solution

You should use a scrollView.

-(void)viewDidLoad{

scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];

scrollView.delegate = self;
scrollView.pagingEnabled = YES;
[scrollView setScrollEnabled:NO];
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;

[scrollView setContentSize:CGSizeMake(320*pageCount, 480)];

for(int i = 0; i < pageCount; i++){

//Create your labels and segmented control here

}

}

-(void)nextButtonPressed{
int currentPage = (scrollView.contentOffset.x/320);
int nextPage = currentPage + 1;

 [scrollView scrollRectToVisible:CGRectMake(320*nextPage, scrollView.frame.origin.y, scrollView.frame.size.width, scrollView.frame.size.height) animated:NO];

}

The concept is creating a scrollView that will contain all your pages. You will have a int which I called pageCount. So each time you enable next button and it is pressed by the user, the scrollView will scroll to the next page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top