key-value-observing

iPhone KVO between two classes

霸气de小男生 提交于 2019-12-02 14:19:31
I have two classes in my app class A and Class B. Both class A and B are instances of UIViewController. Class A has a button that when pushed pushes class B onto the stack. Class B has a string that class A would like to observe and update it's interface with as needed. I've been able to use: [self addObserver:self forKeyPath:@"name" options:0 context:NULL]; in class B to view the changes to the string. When i try and use the following in class A viewWillAppear method: ClassB *b = [[ClassB alloc]init]; [b addObserver:self forKeyPath:@"name" options:0 context:NULL]; and add the method: (void

Inline KVO of a Property in another view controller

怎甘沉沦 提交于 2019-12-02 13:48:01
问题 I have a vc with a dynamic var "value" and i need to know when it's changed in a closure in the calling cv. target vc: @objc dynamic var value: String = "" source: if let vc: TagButtonPopupViewController = sb.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("TagPopupViewController")) as? TagButtonPopupViewController { // configure vc vc.value = sender.title // observe _ = vc.observe(\.value) { (tbvc, change) in print("new string") } // present popup presentViewController(vc,

uiwebview with header and footer

夙愿已清 提交于 2019-12-02 13:43:00
I am trying to add header and footer (both of them as UIViews ) but for some reason my footer sticks to the bottom, I'm using the KVO method for watching my content size. I'm presenting here the method where I think the problem is: - (void)updateLayout { // Update the frame of the header view so that it scrolls with the webview content CGRect newHeaderFrame = self.headerView.frame; CGRect newFooterFrame = self.footerView.frame; newHeaderFrame.origin.y = -CGRectGetMinY([self.webView convertRect:self.innerHeaderView.frame toView:self.webView.scrollView]); newFooterFrame.origin.y = self.webView

A solution to track a batch of HTTP requests in swift 3.0

拈花ヽ惹草 提交于 2019-12-02 12:50:00
I am using swift 3.0 running under iOS 10.0 and I want to craft some code that fires when a batch condition is met. for i in 0 ..< rex { async code, disappears and does it stuff } Imagine the async code is a collection of URL requests, that basically background as soon as I loop thru them. Now how can I fire off more code when "rex" requests have completed? I thought of setting up a timer to watch and check every second, but its surely not a good solution. I thought kicking off another thread to simply watch the data being collected, and fire when its quota is full, but well that's worse then

Inline KVO of a Property in another view controller

…衆ロ難τιáo~ 提交于 2019-12-02 06:05:24
I have a vc with a dynamic var "value" and i need to know when it's changed in a closure in the calling cv. target vc: @objc dynamic var value: String = "" source: if let vc: TagButtonPopupViewController = sb.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("TagPopupViewController")) as? TagButtonPopupViewController { // configure vc vc.value = sender.title // observe _ = vc.observe(\.value) { (tbvc, change) in print("new string") } // present popup presentViewController(vc, asPopoverRelativeTo: sender.bounds, of: sender, preferredEdge: NSRectEdge.maxY, behavior: NSPopover

This class is not key value coding-compliant for the key…why?

做~自己de王妃 提交于 2019-12-02 01:01:47
问题 I've linked output from the IB to the code, as shown below. class DiaryTableViewCell: UITableViewCell { @IBOutlet weak var TitleLabel: UILabel! @IBOutlet weak var SubTitleLabel: UILabel! @IBOutlet weak var leftImageView: UIImageView! @IBOutlet weak var rightImageView: UIImageView! } Here, I'm registering the class: override func viewDidLoad() { self.title = "My Diary" cellNib = UINib(nibName: "TableViewCells", bundle: nil) tableView.registerClass(DiaryTableViewCell.classForCoder(),

Change dictionary in KVO always contains NULL for selectionIndex

不羁岁月 提交于 2019-12-01 22:08:21
问题 I'm using KVO to get notification of changes to NSArrayController's selectionIndex [contoller addObserver:self forKeyPath:@"selectionIndex" options:NSKeyValueObservingOptionNew context:NULL]; and when I set the selection using setSelectedObjects: I get notified of selectionIndex changing as I expect. However when I try to get NSKeyValueChangeNewKey from the change dictionary it always returns NULL. Printing the dictionary shows: { kind = 1; new = ""; } Is this because the selectionIndex value

This class is not key value coding-compliant for the key…why?

半城伤御伤魂 提交于 2019-12-01 21:18:16
I've linked output from the IB to the code, as shown below. class DiaryTableViewCell: UITableViewCell { @IBOutlet weak var TitleLabel: UILabel! @IBOutlet weak var SubTitleLabel: UILabel! @IBOutlet weak var leftImageView: UIImageView! @IBOutlet weak var rightImageView: UIImageView! } Here, I'm registering the class: override func viewDidLoad() { self.title = "My Diary" cellNib = UINib(nibName: "TableViewCells", bundle: nil) tableView.registerClass(DiaryTableViewCell.classForCoder(), forCellReuseIdentifier: kCellIdentifier) } But I keep getting the following runtime error: *** Terminating app

MKMapView constantly monitor heading

落爺英雄遲暮 提交于 2019-12-01 13:35:39
I'm rendering some content in a layer that sits on top of my MKMapView . The whole thing works great with the exception of rotation. When a user rotates the map I need to be able to rotate what I'm rendering in my own layer. The standard answer I found is to use: NSLog(@"heading: %f", self.mapView.camera.heading"); The issue with this is that the content of the heading variable only updates when the pinch/rotate gesture is ending, not during the gesture. I need much more frequent updates. There is no heading property on the mapView itself. I thought maybe using KVO like such: // Somewhere in

KVO Dispatcher pattern with Method as context

﹥>﹥吖頭↗ 提交于 2019-12-01 11:16:52
问题 I've been trying to employ what looks like a very clever KVO pattern that resolves a selector to a Method pointer that can be passed as the context. The last part of the part of the pattern is giving me some troubles: - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { Method m = (Method)context; (void(*)(id,SEL,id,id,id))(m->method_imp)(owner, m->method_name, keyPath, object, change); } Specifically the part where the