質問

working on an ios app with objective c and using xcode. I have a class that inherits from another class that inherits from UIResponder and it contains a view. I have a touchesBegan within the sub class but the event only gets called when running the app in debug/dev mode. when i make a production/release build the touch event is not getting called.

// Basic viewcontroller protocol
@protocol SubViewController
    - (void)viewDidAppear:(BOOL)animated;
    - (void)viewDidDisappear:(BOOL)animated;
    - (void)viewWillAppear:(BOOL)animated;
    - (void)viewWillDisappear:(BOOL)animated;
    - (void)viewDidLoad;
    -(UIView *)view;
@end


@interface SubViewController : UIResponder<SubViewController> {
}

/////////////////////////////////////////////////////////////////////////////////


// A custom subview controller
//

@interface mySubViewController : SubViewController {

}

and within mysubviewcontroller class i have

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   //some code and magic
}

Now as i said running this in debug is fine but the touch event is ignored in release. any tips, ideas or questions to help clarify this for you please say. thanks in advance

edit: i seen this in the doc "If you override this method without calling super (a common use pattern), you must also override the other methods for handling touch events, if only as stub (empy) implementations." so i stubbed in all the other touch events but no change on release build

役に立ちましたか?

解決

As you're not subclassing UIViewController (which does this automatically), you need to add your responder to the responder chain manually.

A UIViewController's position in the responder chain is between its view and the view's superview, so to get the same behavior, you need to override nextResponder in both your view and the controller that manages it. The view should return the controller and the controller should return the view's superview.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top