Check the inlet filter, it is in the pipe where the water pipe connects to the shower, it looks like a little basket.
If this is blocked it will restrict the incoming pressure and will act as though it has low water pressure, this will in turn cause the water pressure switch to open and so taking away the electricity supply to the heater to prevent scalding. Once the water pressure builds back up by forcing itself through the blocked filter the switch will make again and you will get hot water again, hence the cycling between hot and cold. But also as Durham has said low pressure will give the same symptoms. Do you live a hard water area, if so it could be a build up of limescale, you may need to fit an additional filter if this is the case.
Cheers...........Howard