Dear Stack overflow geniuses,
I have already done a simple tableViewController
page to my app, but now I need something a bit more advanced. I have a UI setup with links, labels, text boxes, and then a table of data at the end, so far my view looks like this:
I want to add a Table underneath the text box area and have it scrollable, how exactly do I structure my view controllers and how do I pass data from controller 1 --> controller 2?
I tried changing my current UIViewController
to a tableViewController
but I got some kind on inconsistency exception.
So what are my choices?
UIViewController
Here is the loading code I have so far for the main view controller, I guess where I am stuck, is if I create an outlet from my "tableview" to this UIView
, how do I call code to "fill up" the table, without creating a separate standalone view controller.
Here is my code so far:
[self.objectManager getObjectsAtPath:@"/api/workorder/GetWorkOrderDetail"
parameters:params
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"It Worked");
_workOrders = mappingResult.array;
//paint screen
WorkOrderBig *mainWorkOrder = [_workOrders objectAtIndex:0];
self.lblWorkOrderId.text = mainWorkOrder.WorkOrderId;
self.lblPO.text = mainWorkOrder.PO;
self.lblSupervisor.text = mainWorkOrder.Supervisor;
self.lblPriority.text = mainWorkOrder.Priority;
self.lblStatus.text = mainWorkOrder.Status;
self.lblReceivedDate.text = [CommonUtils GetStringFromDate:mainWorkOrder.ReceivedDate];
self.lblDueDate.text = [CommonUtils GetStringFromDate:mainWorkOrder.DueDate];
WorkOrderProblem *problem = [mainWorkOrder.Problems objectAtIndex:0];
self.txtProblem.text = problem.Description;
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"What do you mean by 'there is no coffee?': %@", error);
}];
This is more of an architecture question and I can choose to do this the right way, so please suggest away at what might be the best way to proceed, Thanks!
It would not be unreasonable to make your current view controller conform to the UITableViewDataSource
and UITableViewDelegate
protocols. This would allow you to populate and respond to the table view. However, this is likely to grow your class's implementation quite a bit. If you do do this, it would be advisable to declare the conformity in a private extension at the top of your .m
.
Another option would be to create a separate class that conforms to the two delegates. Then you would just maintain an instance of this class as a private member of your current controller. In your viewDidLoad:
you would instantiation the class and set it as the delegate and data source of the table view.
Yet another option is to add a subclass of UITableViewController
as a child controller of your current view controller.
objc.io did a great job of covering this in an article of their first issue: lighter view controllers: clean table view code.