18 Mar 2014, 20:33
Generic-user-small

Christoph Lipp (3 posts)

Hi there

I’m currently reading the book (really great so far!) and I had to rewrite the code a little in order to find the coffee pin on the map.

In figure 27 there’s an elements listing. According to the screenshot the pins and the mapview are available as elements on the window object. But it looks like this changed in the latest iOS releases.

The pins are now childs of the mapview. Which means the following code snippet from the book (chapter 5, at the bottom of page 66) does not work anymore:

pinNamed: function(name) {
    log("Looking up", name, "on the map");
    var elements = this.window().elements();
    return elements["POI: " + name];
}

Instead I slightly adjusted the method and changed it to this:

pinNamed: function (name) {
		log("Looking up", name, "on the map");
		var elements = this.window().elements()[1].elements(); // 0 = Toolbar, 1 = MapView, 2 = UINavigationBar
		return elements["POI: " + name];
	}

Please note that I access the object at array index 1. Unfortunately I couldn’t find a way to solve it a little nicer. I actually expected a method on window, something like mapViews(). Is it possible to filter out mapviews with predicates?

Best regards, Christoph

20 Mar 2014, 17:47
Avatar_pragsmall

Jonathan Penn (43 posts)

Yeah, Apple’s been changing the view hierarchy around the map views quite a bit across iOS 6, 7 and 7.1. I’m waiting for things to settle down before even attempting an update to the book.

You’re solving it the way I would, as well. As far as predicates, you really can only filter it out by incorporating the identifier name somehow.

  You must be logged in to comment