Câu hỏi phỏng vấn Xamarin
Câu hỏi

What is Selector...

Câu trả lời

In Xamarin.iOS, a Selector is a class that represents an Objective-C selector in managed code. It is part of the ObjCRuntime namespace and is used to interact with Objective-C methods from C# code. The Selector class allows developers to create and manage selectors, which are essentially pointers to method names in Objective-C.

Key Features of the Selector Class:

  1. Creation:

    • Selector(IntPtr): Creates a selector from an unmanaged pointer to the Objective-C selector.
    • Selector(String): Creates a new selector and registers it with the Objective-C runtime.
  2. Properties:

    • Handle: A pointer to the unmanaged selector representation.
    • Name: The name of the selector.
  3. Methods:

    • Equals(Object): Compares two objects for equality.
    • Equals(Selector): Compares two selectors for equality.
    • FromHandle(IntPtr): Creates a managed selector wrapper based on the native handle.
    • GetHandle(String): Returns the handle to the specified Objective-C selector.
    • GetHashCode(): Returns the selector's hash code.
    • Register(IntPtr): Creates a new selector instance for the specified Objective-C selector.
  4. Operators:

    • Equality(Selector, Selector): Determines if two selector objects are equal by comparing their native handles.
    • Inequality(Selector, Selector): Determines if two selector objects are different by comparing their native handles.

Usage Example:

In Xamarin.iOS, you can use the Selector class to bind actions to UI elements, such as a UIButton. For instance, you can create a selector for a button click event and bind it to a method in your C# code.

csharp Copy
using ObjCRuntime;
using UIKit;

public class MyViewController : UIViewController
{
    UIButton myButton;

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        myButton = new UIButton(UIButtonType.System);
        myButton.SetTitle("Click Me", UIControlS...
expert

expert

Gợi ý câu hỏi phỏng vấn

junior

Explain Lifecycle methods of Xamarin.Forms app

middle

What is Behaviors? Give some examples where we should use Behaviors?

expert

What is the disadvantage of Xamarin to using for example Objective-C or Java for iOS and Android
separately?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào