//Basic idea is to transition to a particular state from current state whenever triggered //and then calling the Enter method which loads the required view from a .xib file (from //Views folder) into the superview. Just before the transition we call the Exit method of //current state so that the previous view is removed from the superview. void TransitionToState(States _currentState, Triggers _trigger) { currentState.Exit(); switch (_currentState) { case States.Idle: if (_trigger == Triggers.Load) { currentState = new LoadingState(); } break; case States.Loading: if (_trigger == Triggers.ShowContent) { currentState = new ContentState(); } else if (_trigger == Triggers.ShowEmpty) { currentState = new EmptyState(); } else if (_trigger == Triggers.ThrowError) { currentState = new ErrorState(); } break; } }
public ViewStateMachine(States initialState) { if (initialState == States.Idle) { currentState = new IdleState(); } }