0

i have a segmented control with 4 segment

segment 1 - i need a page control to swipe through photos <- -> left & right. 1- 4 photos max

Segment 2 & 3 - i need a table view

Segment 4 - i need it to be able to play video

i'm currently doing this

- (IBAction)infoAction:(id)sender {

NSString * selectedTitle = [info titleForSegmentAtIndex:[info selectedSegmentIndex]];


NSLog(@"Selected Title = %@",selectedTitle);//test


switch ([info selectedSegmentIndex])

{   case 0:
    {
        test.text = [frogInfo.imageFiles objectAtIndex:0];
        test.textColor = [UIColor whiteColor];
        [tempImageView setImage:[UIImage imageNamed:@"Detail1Temp.png"]];
        break;

    }


    case 1:

    {    

        test.text = frogInfo.description;
                    test.textColor = [UIColor whiteColor];
        [tempImageView setImage:[UIImage imageNamed:@"Detail2Temp.png"]];
        break;

    }

    case 2:

    {
        test.text = frogInfo.distribution;
        test.textColor = [UIColor whiteColor];
        [tempImageView setImage:[UIImage imageNamed:@"Detail3Temp.png"]];
        break;

    }

    case 3:

    {

        test.text = [frogInfo.videoFiles objectAtIndex:0];
        test.textColor = [UIColor whiteColor];
        [tempImageView setImage:[UIImage imageNamed:@"Detail4Temp.png"]];
        break;

    }

}

}

picture with page control

enter image description here

section tableview

enter image description here

Based on what i will like to do, is it possible ? in this switch case function ?

can anybody show or have any link to tutorial on how to work out the page control swiping ?

thanks for reading

Des

Desmond
  • 5,001
  • 14
  • 56
  • 115
  • 1
    Did you considered using UITabBar instead of segmented control? If the use of tabbar is not acceptable you will have to switch views based on selected segment manually, the UISegmentedControl does not provide any kind of view for you to place your controls on. – mja Oct 05 '11 at 13:37
  • this is one of the view, i have tab bar for other views,basically most of the segment are table views except the segment 1, which are pictures – Desmond Oct 05 '11 at 13:42
  • well then you probably have to hide&unhide a scrollview for the first segment, a tableview connected to one of the datasources (one for each segment) and a MPMoviePlayer for the last segment. – mja Oct 05 '11 at 13:45
  • will u be able to show me a tutorial on how to do the scrollview image ? – Desmond Oct 05 '11 at 13:53
  • 1
    refer to this post: http://stackoverflow.com/questions/1595389/learning-the-basics-of-uiscrollview – mja Oct 05 '11 at 13:57

1 Answers1

0

I have done something very similar although I used a UISlider instead of segmented control - What you need is a pageable UISCrollview with 4 equal sized pages (UIViews) loaded horizontally one after another if take-up the entire width of an iPhone each page is 320 wide and the content size width of your scrollview will be 1280. Tie up the UIsegmented controls to scroll the pages programatically:

assuming a page width of 320:

     -(IBAction)movepage:(id)sender {
      int xloc = (segmentedController.selectedSegmentIndex * 320);
      CGRect fieldrect = CGRectMake(xloc,0,320, pagesize.height);

    [scrollView scrollRectToVisible:fieldrect animated:YES];

}

To load the scrollview and manage the pagecontroller:

pagectrl.numberOfPages = 4;
pagectrl.currentPage = 0;

scrollView.pagingEnabled = YES;
scrollView.contentSize=CGSizeMake(320* pagectrl.numberOfPages, 500);
scrollView.showsVerticalScrollIndicator = NO;
scrollView.showsHorizontalScrollIndicator = YES;
scrollView.bouncesZoom = NO;
scrollView.decelerationRate = UIScrollViewDecelerationRateFast;
scrollView.scrollsToTop = NO;


scrollView.delegate = self;
search_url.delegate = self;
user.delegate = self;
password.delegate = self;
rpc_code.delegate = self;


// add pages

int page = 0;

CGRect frame = scrollView.frame;
pagesize = frame.size.width;
frame.origin.y = 0;
frame.origin.x = frame.size.width * page;
firstView.frame = frame;
[scrollView addSubview:firstView];

page ++;
frame.origin.x = frame.size.width * page;
locsubView.frame = frame;
[scrollView addSubview:locsubView];

page ++;
frame.origin.x = frame.size.width * page;
QRgensubView.frame = frame;
[scrollView addSubview:QRgensubView];

page ++;
frame.origin.x = frame.size.width * page;
scansubView.frame = frame;
[scrollView addSubview:scansubView];

page ++;
frame.origin.x = frame.size.width * page;
symbologysubView.frame = frame;
[scrollView addSubview:symbologysubView];


[self registerForKeyboardNotifications];

 CGRect fieldrect = CGRectMake(0,0,320, pagesize);

 [scrollView scrollRectToVisible:fieldrect animated:YES];  //goto 1st page

}

Note you may need to control or manage the user ability to scroll the scroll view - you do that by setting up the scrollview delegate - the code below is not fitted to your exact requirement but I'm sure you can figure out the rest!

 - (void)scrollViewDidScroll:(UIScrollView *)sender
   {
   // We don't want a "feedback loop" between the UIPageControl and the scroll delegate  in

  // which a scroll event generated from the user hitting the page control triggers updates from

   // the delegate method. We use a boolean to disable the delegate logic when the page control is used.

   //  if (pageControlUsed)
   //  {
  // do nothing - the scroll was initiated from the page control, not the user dragging
  //       return;
  //   }

  // Switch the indicator when more than 50% of the previous/next page is visible

  int page = floor((scrollView.contentOffset.x - pagesize / 2) / pagesize) + 1;
  pagectrl.currentPage = page;



  // A possible optimization would be to unload the views+controllers which are no longer visible
 }
Paulo
  • 1,245
  • 10
  • 8