Felix K.
Felix K.

Reputation: 6281

iOS / MonoTouch: Become first responder

I have a single view in my application which does not receive any events from iOS. I tried to call "BecomeFirstResponder" but this does not work and the method returns false.

Here is the code which creates the view:

_Window = new UIWindow(UIScreen.MainScreen.Bounds);
View = new ApplicationView(this);
_Window.RootViewController = new UIViewController();
_Window.Add(View);
_Window.MakeKeyAndVisible();

Thats the code which handles the input( ApplicationView; Base class is iPhoneOSGameView which has UIView as base class ):

public override void TouchesBegan(NSSet touches, UIEvent evt)
{
    foreach (UITouch item in touches.ToArray<UITouch>())
    {
        _Stage.MapTouchesBegan(new TouchEvent((Int32)item.Handle, item.LocationInView(this)));
    }
}

The method is never called.

Thanks in advance

Upvotes: 1

Views: 895

Answers (1)

Krumelur
Krumelur

Reputation: 33048

Your code looks wrong. The UIViewController assigned to root does nothing. Also I think you meant to use window.AddSubview(). Does the code above even build? Does your view fill the entire screen? It only will receive touches inside its frame.

You might want to take a look at the basics of the model view controller concept (http://developer.apple.com/library/mac/ipad/#documentation/General/Conceptual/DevPedia-CocoaCore/MVC.html) and also at some samples that get you started with iOS development in Monotouch (https://github.com/xamarin/monotouch-samples)

Upvotes: 1

Related Questions