delegates

Swift 3.0 Delegate Protocol doesn't work

不问归期 提交于 2020-01-05 04:40:13
问题 I have made delegate protocol within two view controllers. but the delegate method doesn't call on my code snippet. what is the reason for that. I couldn't find out the issue kindly post your suggestions to relive this issue. Main View controller class ViewController: UIViewController, testDelegateMethod { override func viewDidLoad() { super.viewDidLoad() let vw = testViewController() vw.delegateTest = self let push = self.storyboard?.instantiateViewController(withIdentifier:

Why does Apple use assign rather than weak to store a delegate?

心已入冬 提交于 2020-01-04 10:19:00
问题 Some Cocoa and Cocoa Touch classes declare their delegate properties as assign rather than weak , which forces users of the class to nil out the property in dealloc -(void)dealloc { self.imageScrollView.delegate = nil; self.tableView.delegate = nil; self.tableView.dataSource = nil; } Which is very cumbersome. Why would Apple do it this way? 回答1: The reason why is that not all system classes have been compiled with ARC. You may implement a dealloc method if you need to manage resources other

Why does Apple use assign rather than weak to store a delegate?

走远了吗. 提交于 2020-01-04 10:18:08
问题 Some Cocoa and Cocoa Touch classes declare their delegate properties as assign rather than weak , which forces users of the class to nil out the property in dealloc -(void)dealloc { self.imageScrollView.delegate = nil; self.tableView.delegate = nil; self.tableView.dataSource = nil; } Which is very cumbersome. Why would Apple do it this way? 回答1: The reason why is that not all system classes have been compiled with ARC. You may implement a dealloc method if you need to manage resources other

Rails 4 welcome wizard, how to correct this code to make it work for rails 4?

天涯浪子 提交于 2020-01-04 09:02:31
问题 Try to build a welcome wizard and try to get existing rails code to be ported to be rails 4 compatible. Based mostly on previous great answer: https://stackoverflow.com/a/17255451/355281 I try to call http://books:3000/welcome/basics This results in: Circular dependency detected while autoloading constant WelcomeController app/controllers/welcome_controller.rb class Welcome::ApplicationController < ::ApplicationController layout "welcome" before_filter :authentice_user! end app/controllers

Accessing protocol property in Swift class

大兔子大兔子 提交于 2020-01-04 05:33:35
问题 I am trying to use a protocol to pass an array from one class to another. protocol PinsArray { var dataArray: [LocationPost] {get set} } When I am trying to create a delegate in class, which should receive it does not work. I cannot access the property var delegate = PinsArray.self Like this: delegate.dataArray It says that "instance member 'dataArray' cannot be used on type PinArray" So what do I do wrong? 回答1: You are assigning the type of PinsArray to delegate instead of assigning an

C# generic delegate type inference

亡梦爱人 提交于 2020-01-04 05:15:13
问题 Why can't the C# compiler infer T to int in the specified example? void Main() { int a = 0; Parse("1", x => a = x); // Compiler error: // Cannot convert expression type 'int' to return type 'T' } public void Parse<T>(string x, Func<T, T> setter) { var parsed = .... setter(parsed); } 回答1: Method type inference on a lambda requires that the types of the lambda parameters be already known before the types of the returns are inferred. So for example if you had: void M<A, B, C>(A a, Func<A, B> f1,

Sort a list by Code, Then by Name

社会主义新天地 提交于 2020-01-04 02:07:05
问题 I have a list of objects. I sort this list by Code by writing this line: Result.Sort(delegate(Position p1, Position p2) { return p1.Code.CompareTo(p2.Code); }); But I want to sort this line first by Code and then by Name. How to I do this? 回答1: Without LINQ: Result.Sort(delegate(Position p1, Position p2) { var byCode = p1.Code.CompareTo(p2.Code); return byCode == 0 ? p1.Name.CompareTo(p2.Name) : byCode; }); Or the same logic using comparers: Result.Sort(new PositionComparer()); class

C# using properties with value types with Delegate.CreateDelegate

不问归期 提交于 2020-01-04 01:56:06
问题 Using Jon Skeet's article Making reflection fly and exploring delegates as a guide, I am trying to use the Delegate.CreateDelegate method to duplicate properties as delegates. Here's an example class: public class PropertyGetter { public int Prop1 {get;set;} public string Prop2 {get;set;} public object GetPropValue(string propertyName) { var property = GetType().GetProperty(propertyName).GetGetMethod(); propertyDelegate = (Func<object>)Delegate.CreateDelegate(typeof(Func<object>), this,

Problem with anonymouse delegate within foreach

夙愿已清 提交于 2020-01-03 17:52:55
问题 public Form1() { InitializeComponent(); Collection<Test> tests = new Collection<Test>(); tests.Add(new Test("test1")); tests.Add(new Test("test2")); foreach (Test test in tests) { Button button = new Button(); button.Text = test.name; button.Click+=new EventHandler((object obj, EventArgs arg)=>{ this.CreateTest(test); }); this.flowLayoutPanel1.Controls.Add(button); } } public void CreateTest(Test test) { MessageBox.Show(test.name); } } when i click the button witch text is 'test1', the

Disable Resharper with comment

走远了吗. 提交于 2020-01-03 17:48:12
问题 Edit: Problem is solved by updating. Resharper is really annoying me and marking code that is 100% correct as wrong, it keeps wanting me to change an Action to an Action<T1,T2...Tn> when this obviously incorrect. It flashes everytime I type something so is really distracting. Is there a way to disable resharper totally inbetween two comments? Or how do you disable only for this warning? Edit: There is no hint on the left to disable this using comments. The menu that pops up when you press Alt