Question

I'm writing an app that tests some RPCs sent over a tcp transport to some connected hardware. There are approximately 35 different RPCs with varying inputs.

The user selects one of the messages they want to send and a view controller is pushed that asks for input specific to that RPC. The inputs for the RPCs can change based on what the user has done previously during the session. Some common UI objects used would be text, sliders, and pickers.

My question is about code organization. Right now I can think of two broad strategies for implementing this application.

The first is to use storyboards and create a custom view controller for every one of the messages. This is probably the easiest and most understandable, but messiest implementation.

The second is to create a custom view controller that responds to messages to layout input fields and build RPCs. This requires a model backing each of the different types of RPCs and some long case statements to differentiate between the different types.

Does Objective-C have a common design pattern for handling this type of situation?

Was it helpful?

Solution

One nice way of handling this is to use a tableview. Write a cell for each of your possible input types (these might do their layouts in code or be backed by NIBs). Register all the cell types with the table view, and return the ones you need based on the current RPC from -tableView:cellForRowAtIndexPath:.

I'd probably just generate a list of strings that describe the inputs when the view is first loaded with a new RPC, and reference that to figure out which cell is needed for a given indexPath.

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