I'm trying to understand the pattern for using ResponsdsToSelector in Monotouch. For example, the following translation doesn't work. (LayoutMargins is used to set the cell indent in iOS 8)
Objective C:
if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[tableView setLayoutMargins:UIEdgeInsetsZero];
}
to Monotouch
if (this.TableView.RespondsToSelector(new Selector("setLayoutMargins")))
this.TableView.LayoutMargins = UIEdgeInsets.Zero;
I'm pretty sure I just have a problem with my naming "setLayoutMargins". I've tried "LayoutMargins" too. Can anyone help 1) fix this statement and 2) help me understand the naming convention / pattern?
Thanks!
I'm pretty sure I just have a problem with my naming "setLayoutMargins"
The selector ends with a :
in ObjC and needs to have in in C# too, i.e.:
if (this.TableView.RespondsToSelector(new Selector("setLayoutMargins:")))
Note: that extra :
means there's an argument required when calling the selector. That's why the set*
has it while the getter does not.
An alternative to checking for selectors is to use a version check.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With