I asked this question over on Stack Overflow and based on the answers I have recieved what I want to do should be possible however I am still leaning towards it can not be done.
I have a NSTimer updating several views via a delegate on a set timeframe.
I thought it would look nice to place my views into a split view on an iPad as well as the iPhone 6x Plus. I successfully moved my views into a split view controller however when I rotate the device only one side is updated via the delegate (master is updated or detail is updated) depending on where I was in the app when I rotate the device from portrait. That side continues to Update while the device is in the "Split View Mode". If I click on a new row in the master and the master was updating (detail was not) then the detail starts updating and the master stops.
I have a MasterTimer class that is instantiated once and only once when the app is launched or returns to the foreground that has several delegate methods (protocol). This masterTimer class has an instance of a NSTimer that is firing updates to additional Items. When the Timer fires it notifies through the delegate that something has changed and that the views should be updated. My views are registered to listen for the delegate. When the device is in portrait mode, the views and the app are working as one would think. It breaks apart when the views are in a split view.
I have a hunch based on the fact that it works as advertised that I acctually cant update both sides of a split view when both the master and the detail are on screen. Is this the case? If it is not what am I doing wrong.
Here is some sample code that hopefully explains what I am doing:
MasterTimer:
import UIKit
protocol MasterTimerDelegate {
func masterTimerDidUpdate(item: Item, forGroup group: Group)
func masterTimerDidUpdateAllItems()
func masterTimerDidUpdateProgressForItem(item: Item, forGroup group: Group, withProgressCompleted progress: Double)
}
class MasterTimer: NSObject {
//...... (stuff here)
func ticToc() { // called by the NSTimer
//do stuff
delegate?.masterTimerDidUpdate(item, forGroup: group)
delegate?.masterTimerDidUpdateAllItems()
delegate?.masterTimerDidUpdateProgressForItem(item, forGroup: group, withProgressCompleted: item.progressDuration)
}
}AllGroupsView: What should be the MasterView in the SplitView on landsscape
class AllGroupsViewController: UITableViewController, GroupDetailViewControllerDelegate, UINavigationControllerDelegate, MasterTimerDelegate {
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
// do stuff
tableView.reloadData()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "reloadList:", name: "reloadList", object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "didRotate:", name: UIDeviceOrientationDidChangeNotification, object: nil)
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
navigationController?.delegate = self
masterTimer.delegate = self
// do stuff
}
func reloadList(notification: NSNotification) {
if (self.tableView != nil) {
// do stuff
self.tableView.reloadData()
}
}
func didRotate(notification: NSNotification) {
if (self.tableView != nil) {
// do stuff
// trying to reset the delegate on rotation thinking that this would help. It does not
masterTimer.delegate = self
self.tableView.reloadData()
}
}
//do a bunch of stuff
// Start of delegate implementation
func masterTimerDidUpdate(item: Item, forGroup group: Group) {
// I dont care about this one in this view. Will make optional when I do some cleanup but is currently required
}
func masterTimerDidUpdateAllItems() {
for group in groups {
if let cell = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: groups.indexOf(group)!, inSection: 0)) as? GroupCell {
configureLabelsForCell(cell, forGroup: group)
cell.progressCirclesForGroupView.updateGroupProgressCircles(group)
}
}
}
func masterTimerDidUpdateProgressForItem(item: Item, forGroup group: Group, withProgressCompleted progress: Double) {
// I dont care about this one in this view. Will make optional when I do some cleanup but is currently required
}
}For brevity the GroupViewController is similar to the code above. Trust me they are both working correctly when in portrait and they were working before I tried to add in the split view for the iPad and the iPhone 6x Plus.
Again the answers I have recieved on stack overflow lead me to believe that there should be no reason that I can't update both the master and the detail view in landscape mode. The only thing I can think of why this is not working for me is that If I rotate the device from what will be the master view that it is the only one that is technically on the main queue and that the detail view is drawn and then released, and vice versa. I could be wrong as I am new to iOS but not other languages and platforms where something like this is doable.
Any tips or answers are much appreciated.