delegates

how to set a tableview delegate

旧城冷巷雨未停 提交于 2019-12-17 18:20:13
问题 I'm trying to use a UITableView without using a nib and without using a UITableViewController . I have added a UITableView instance to a UIViewController Like So mytable = [[UITableView alloc] initWithFrame:CGRectMake(22, 207, 270, 233)]; [mytable setDelegate:self]; [self.view mytable]; Also I have added the following table view methods to my UIViewController (cut for brevities sake) - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath -

Handling app delegates and switching between views

天大地大妈咪最大 提交于 2019-12-17 17:24:39
问题 I'm getting a warning about a semantic issue pertaining to passing a *const _strong to type id and cannot seem to fix it no matter what I change. I have two views at the moment, and have written this code. In iPadSpeckViewController.m, here is the method that should switch between views: -(IBAction) touchProducts { ProductsViewController *controller = [[ProductsViewController alloc] initWithNibName:@"Products" bundle:nil]; controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

Trying to pass data between viewControllers

て烟熏妆下的殇ゞ 提交于 2019-12-17 17:13:14
问题 I have a sequence of 4 viewControllers inside a NavigationController, each grabs a few textFields of input from the user which are stored in a NSMutableDictionary. Each of the VC's set's itself up as the delegate of the nextVC before it segues, it also passes the NSMutDict along. This works fine. What I don't understand is this: Say I have filled in the 5 textFields in VC1. Then I set myself as the delegate of VC2, pass VC2 the dictionary with the input data and segue to VC2. In VC2 I fill in

Is there an actual difference in the 2 different ways of attaching event handlers in C#?

邮差的信 提交于 2019-12-17 16:59:40
问题 In C# is there any real difference (other than syntax) under the hood between: myButton.Click += new EventHandler(myMemberMethod); and myButton.Click += myMemberMethod; ? 回答1: The second method is a shortcut to the first one, it was introduced in C# 2.0 See also this thread. 回答2: They are exactly the same, its called syntax sugar. There are a lot of things that arent needed, to get a better idea of them while programming you should try something like Resharper. It will color the unnecessary

Type of conditional expression cannot be determined (Func)

扶醉桌前 提交于 2019-12-17 16:30:18
问题 When assigning a method to a Func -type, I get the compilation error Type of conditional expression cannot be determined because there is no implicit conversion between 'method group' and 'method group' . This only happens with the ? : operator. The code: public class Test { public static string One(int value) { value += 1; return value.ToString(); } public static string Two(int value) { value += 2; return value.ToString(); } public void Testing(bool which) { // This works Func<int, string>

What does “a field initializer cannot reference non static fields” mean in C#?

此生再无相见时 提交于 2019-12-17 16:27:49
问题 I don't understand this error in C# error CS0236: A field initializer cannot reference the non-static field, method, or property 'Prv.DB.getUserName(long)' For the following code public class MyDictionary<K, V> { public delegate V NonExistentKey(K k); NonExistentKey nonExistentKey; public MyDictionary(NonExistentKey nonExistentKey_) { } } class DB { SQLiteConnection connection; SQLiteCommand command; MyDictionary<long, string> usernameDict = new MyDictionary<long, string>(getUserName); string

Delegates in C#

与世无争的帅哥 提交于 2019-12-17 15:36:34
问题 I`m having some trouble in understanding how delegates in C# work. I have many code examples, but i still could not grasp it properly. Can someone explain it to me in "plain english"? Of course! examples of code will help, but i think i need more of a description of how/why it works. EDIT: Well, the question is: why does delegates work? What is a "flow chart" of the entire process? What are the pre-requisites of using delegates? I hope this makes the question clearer. 回答1: One way to think

NSFetchedResultsContollerDelegate for CollectionView

心已入冬 提交于 2019-12-17 15:27:30
问题 I'd like to use the NSFetchedResultsControllerRelegate in a CollectionViewController. Therefore I just changed the method for the TableViewController for the CollectionView. (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type { switch(type) { case NSFetchedResultsChangeInsert: [self.collectionView insertSections:[NSIndexSet indexSetWithIndex

Cannot find protocol declaration for

佐手、 提交于 2019-12-17 10:58:36
问题 I have two objects, both of which are view controllers. The first (Ill call it viewController1) declares a protocol. The second (which unsurprisingly I will name viewController2) conforms to this protocol. XCode is giving me a build error of: 'Cannot find protocol declaration for viewController1' I have seen various questions on this subject and I am certain it is to do with a loop error, but I just can't see it in my case... Code below.. viewController1.h @protocol viewController1Delegate;

a constructor as a delegate - is it possible in C#?

喜夏-厌秋 提交于 2019-12-17 10:33:24
问题 I have a class like below: class Foo { public Foo(int x) { ... } } and I need to pass to a certain method a delegate like this: delegate Foo FooGenerator(int x); Is it possible to pass the constructor directly as a FooGenerator value, without having to type: delegate(int x) { return new Foo(x); } ? EDIT: For my personal use, the question refers to .NET 2.0, but hints/responses for 3.0+ are welcome as well. 回答1: Nope, the CLR does not allow binding delegates to ConstructorInfo . You can