hi UNIVAC Coder,
there are plenty of things going on here.
the default master-detail VC template model is a good, general place to start; and although it declares the MasterViewController as having
var objects = [Any]()
this array of objects is really (as the program uses it) an array of NSDates. if you change the declaration to
var objects = [NSDate]()
you'll see that what you're trying to do (adding a UITextField to this array) is not really the right direction to take.
if you really want to show the names of bowlers (i.e., strings), start with
var objects: [String] = ["Fred", "Murray", "Ginger", "Rogers"]
then change the insertNewObject function to be
@objc
func insertNewObject(_ sender: Any) {
objects.insert("Inserted Name", at: 0)
let indexPath = IndexPath(row: 0, section: 0)
tableView.insertRows(at: [indexPath], with: .automatic)
}
two small changes in MasterViewController are required, so that you remove casts of the object items as NSDates (change both occurrences)
let object = objects[indexPath.row] // as! NSDate
and one small change is required in DetailViewController to work with Strings rather than NSDates
var detailItem: String? {
didSet {
// Update the view.
configureView()
}
}
now you should have a functioning list-of-strings display application.
from here, editing is a whole new level. two quick thoughts for you to research:
- i highly recommend Mark Moeykins's Moeykens's (Big Mountain Studios) Youtube videos, especially the one titled "Popups to Add Data - Part 13 - Itinerary App" (and this entire series). this shows how you bring up a simply dialog to capture the name of a new bowler in response to pressing the + button, BEFORE you then call insertNewObject to add the bowler's names to the objects array.
- if you want to allow the user to edit names after-the-fact, in place in the UITableView, that's a lot more work. the cells in the UITableView would have to be of a different type (not a Basic UITableViewCell with a simple UILabel, but a custom type with with, yes, a UITextField.) managing this might be beyond where you are now, so i'd recommend putting this off until you really want or need to do it.
hope this helps get you started, and good luck,
DMG