delegation

Delegation not working Swift

雨燕双飞 提交于 2019-12-25 04:13:08
问题 I'm trying to implement the delegation pattern on Swift. The process consists in a popover that is displayed from a UIMenuItem in a text selection on a textView. This popover is a TableViewController that contains some colors. When a cell (or color) is tapped, the selected text changes its color from black to the selected color. I have the following protocol in the sending class: protocol SelectedColorDelegate { func didSelectColorCell(color: UIColor) } Then in the sending class I created

Google Closure event delegation a'la jQuery live/on

雨燕双飞 提交于 2019-12-22 08:18:17
问题 I need to delegate event to newly created elements, I need to attach handler to their creation event. Something similar to: onCreate I do not want to bind the event to the element after the creation by addressing it: jQuery: $(element).click(function(){}); I would prefer something like $.on('document','spawn', '.item', function(e) { if (e.target == this.target) { alert('element created: '+this); } }); Is there a way to do so in google closure? the goal is to attach the event on creating and

How to release an object declared into a method and passed to another method?

扶醉桌前 提交于 2019-12-20 07:45:13
问题 Any idea on how to release the UIImage object picture in this case: - (void)connectionDidFinishLoading:(NSURLConnection *)connection { UIImage *payload = [[UIImage alloc] initWithData:self.activeDownload]; UIImage *picture = [[UIImage alloc] init]; if (payload.size.width != kAppIconHeight && payload.size.height != kAppIconHeight) { CGSize itemSize = CGSizeMake(kAppIconHeight, kAppIconHeight); UIGraphicsBeginImageContext(itemSize); CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width,

Delegated event handler without jQuery

喜欢而已 提交于 2019-12-20 03:08:47
问题 Made this example: https://jsfiddle.net/d8ak0edq/2/ document.getElementById('outer').oncontextmenu = function() { return false; }; outer = document.getElementById('outer'); outer.addEventListener('mousedown', foo); function foo(evt) { if (evt.which === 1) { evt.target.style.backgroundColor = 'red'; } else if (evt.which === 3) { evt.target.style.backgroundColor = 'blue'; } } /* $outer = $('#outer'); $outer.on('mousedown', 'div', foo); function foo(evt) { if (evt.which === 1) { $(this).css(

Delegated event handler without jQuery

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 03:08:05
问题 Made this example: https://jsfiddle.net/d8ak0edq/2/ document.getElementById('outer').oncontextmenu = function() { return false; }; outer = document.getElementById('outer'); outer.addEventListener('mousedown', foo); function foo(evt) { if (evt.which === 1) { evt.target.style.backgroundColor = 'red'; } else if (evt.which === 3) { evt.target.style.backgroundColor = 'blue'; } } /* $outer = $('#outer'); $outer.on('mousedown', 'div', foo); function foo(evt) { if (evt.which === 1) { $(this).css(

What is delegation? When would I want to use it?

风流意气都作罢 提交于 2019-12-19 17:41:47
问题 In OOP, a term delegation is mentioned. How is this modelled in a class? I searched on yahoo etc but got links to delegates. 回答1: Imagine you have the classes Car and Engine : public class Car { private Engine engine = new Engine(); //or inject it externally public void start() { engine.start(); } } In this example the Car delegates to the underlying Engine . The user of the car cannot directly start the engine (unless he is a mechanic). But he can tell the car to start, and the car in turn

How does DelegatingVehicleTracker (p. 65 Goetz) return a “live” view?

蹲街弑〆低调 提交于 2019-12-19 07:43:51
问题 On page 65 and 66 of Java Concurrency in Practice Brian Goetz lists the following code: @ThreadSafe public class DelegatingVehicleTracker { private final ConcurrentMap<String, Point> locations; private final Map<String, Point> unmodifiableMap; public DelegatingVehicleTracker(Map<String, Point> points) { locations = new ConcurrentHashMap<String, Point>(points); unmodifiableMap = Collections.unmodifiableMap(locations); } public Map<String, Point> getLocations() { return unmodifiableMap; }

Difference between Decorator pattern and Delegation pattern

懵懂的女人 提交于 2019-12-18 12:12:45
问题 What is the difference between Decorator pattern and Delegation pattern (if there is any) ? I don't want to know just about implementation details but also about use case differencies and subjective point of view how to use them. Decorator pattern Delegation pattern EDIT : Can you point to source code (in OS project) where these pattern (especially Delegation, because Decoration is used in Java IO classes) are used. I'm looking for some real usage not just dummy example. Maybe these patterns

Difference between Strategy pattern and Delegation pattern

ぃ、小莉子 提交于 2019-12-18 11:29:36
问题 What is the difference between Strategy pattern and Delegation pattern (not delegates)? 回答1: the strategy pattern is a very specific design solution to a common software problem. the strategy pattern implies that there will be an interface called Strategy (or with Strategy as part of the name). this interface should have a method called execute(). one or more concrete classes called something like ConcreteStrategyA, ConcreteStrategyB, etc. that implement the Strategy interface. there should

Javascript event delegation, handling parents of clicked elements?

自古美人都是妖i 提交于 2019-12-17 22:52:03
问题 http://jsfiddle.net/walkerneo/QqkkA/ I've seen many questions here either asking about or being answered with event delegation in javascript, but I've yet to see, however, how to use event delegation for elements that aren't going to be the targets of the click event. For example: HTML: <ul> <li><div class="d"></div></li> <li><div class="d"></div></li> <li><div class="d"></div></li> <li><div class="d"></div></li> <li><div class="d"></div></li> <li><div class="d"></div></li> </ul>​ CSS: ul{