ios - Get only the NAME of PARENT CLASS through any of its UI elements (eg. button, label, textfield) -


this question has answer here:

i trying class name of uiviewcontroller through 1 of ui elements. when called in following manner, class method returns correct name (eg: myviewcontroller):

nslog(@"class name: %@", nsstringfromclass(self.class)); 

but when called this, returns uiview:

uibutton *button = [[uibutton alloc] init]; [self.view addsubview:button]; nslog(@"class name: %@", nsstringfromclass(button.superview.class)); 

if have reference button object, in class example, how actual name of parent class?

it violates mvc design pattern view directly access view controller it's contained it. if want view communicate view controller, should done through delegate pattern:

first create protocol view controller can implement:

@protocol viewdelegate<nsobject> - (void)viewdiddosomething; @end  @interface myviewcontroller<viewdelegate>  @end  @implementation myviewcontroller - (void)viewdiddosomething {     // react view doing } 

then create custom view responsible holding ui , communicating view controller through delegate:

@interface customview : uiview @property (nonatomic, weak) id<viewdelegate> delegate; @end 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -