0

I've been researching this problem all day and haven't found a suitable solution as yet.

I am trying to create a view similar to Notifications Centre in iOS7. There is a UISegmentControl at the top, On tapping on any of the tabs take you to a different screen. Swiping left or right take you forward or back to the last screen.

I'm looking at implementing this in a UINavigationController that has a UIViewController embedded in it.

I tried to just perform a segue based on the selectedIndex of the UiSegmentControl. This worked okay but crashes when going from one tab to another in a random order. Also, I don't get the swipe to go back. I don't need to swipe to go forward - just back.

I want to go to three different views - which all use the same viewController class (As these views do the same thing.

I'm using storyboards and iOS7 only.

Does anyone have any ideas how this could be done?

Samkit Jain
  • 2,523
  • 16
  • 33
Robert J. Clegg
  • 7,231
  • 9
  • 47
  • 99

2 Answers2

0

Follow this simple approach.

  • Have your UISegmentedControl in navigation bar with items as One, two, three.

  • Have a three UIView in your viewController as view1, view2, view3.

  • Set your UISegmentedControl's target method & set by default index 0 as selected & implement the method.

    [self.segmentedControl addTarget:self action:@selector(changeSegments:) forControlEvents: UIControlEventValueChanged];
    
    -(void) changeSegments:(UISegmentedControl *)segment {
        // set your views alpha depending upon your selection.
    
     }
    

Hope that helps.

Balram Tiwari
  • 5,657
  • 2
  • 23
  • 41
  • Thanks for your help. However I don't want the segment control in the NavigationBar. I was thinking I could switch the views in a container view? I also, really need swipe to go back to last few. – Robert J. Clegg Jan 29 '14 at 11:43
  • Then thats even simpler. Have a UIPageControl & add three pages with, each page corresponding to a view. Implement swipe gesture & then change the selected segment of UISegmentedControl to the index of page you are on. If you need code, I may seek time. – Balram Tiwari Jan 29 '14 at 11:59
  • Thanks you, I will look into this. I've never used UIPageControl. Let me first try it out and if I get stuck I can ask for a little more help? Appreciate your time with this. :) – Robert J. Clegg Jan 29 '14 at 12:05
  • 1
    A cool answer to the new approach you have agreed upon. [UIPageControl + Swipe](http://stackoverflow.com/a/16391892/1307844) – Balram Tiwari Jan 29 '14 at 12:23
  • Was literally just looking at that answer :-). I am trying to figure out how to load three views in the UIPageControl. – Robert J. Clegg Jan 29 '14 at 12:26
  • Tried to follow this tutorial: http://www.wannabegeek.com/?p=168 and tested the sample code. Its not working with a segment control. I don't think UIPageControl is what I am after. :( Thanks though. – Robert J. Clegg Jan 29 '14 at 14:05
  • 1
    Comments going long. Will send you code instead. Ping me at tiwari.balram@gmail.com – Balram Tiwari Jan 29 '14 at 14:30
  • Don't have ping messenger. Sorry: I'm on gmail chat / messages: tanderza@gmail.com – Robert J. Clegg Jan 29 '14 at 14:42
  • How far you are on this ? – Balram Tiwari Feb 01 '14 at 17:00
  • Implemented a custom solution using some of the methods we spoke about. Will mail you tomorrow. – Robert J. Clegg Feb 02 '14 at 19:36
0

I think you should be using a UICollectionView for your different screens. That way you get swipe out of the box.

Then it's just a matter of linking the segmented control to the collection view.

Odrakir
  • 4,254
  • 1
  • 20
  • 52