I have a button that will change the view's class to UIControl
i have typed this line of code but Xcode say it is a error
-(IBAction)button:(id)sender
{
self.view.class = [UIControl class];
}
So guys my question is how to change my view's class to UIControl
class programmatically
You cant change the class type at runtime.
Alternatively you can set your control to stop handling user interactions:
self.userInteractionEnabled = NO;
In objective C you cannot assign the class
property of an object and within instance of UIViewController (which I'm assuming you're code resides in) you cannot assign the view
property outside of loadView
without causing issues.
I think your general question on changing an objective C's class is slightly misguided and you may need reword your question such that it's possible to suggest a way to do what you're trying to do in cocoa.
What are you actually trying to do? Are you attempting to change what's displayed on screen in response to an event? Are you trying to change the behaviour of your view controller's view somehow?
These things are usually done by adding/changing/modifying the view hierarchy of your view controller by adding other UIView instances rather than modifying existing ones.
You can define your own class that inherits form UIControl
easily but there's a lot more you need to do to begin using it in the above example.
@interface CustomClass : UIControl
…
@emd
Can I suggest the following introduction to Objective C and iPhone programming guides form Apple that may shed some light on how to do things in Cocoa.
- Learning Objective C - A Primer
- Programming with Objective C
- iOS App Programming Guide