Calling sub class method from the super class in Objective C - iphone

My original question id here.
Actually I need more clarification about this problem.
Consider the following scenario:
There are three classes in my project. Say A, B & C.
These 3 classes have some common methods with them. So I created an another class (Say D) in which, I added those common methods.
Now Class D is the parent class and Class A,B & C are child classes. That is, Class A,B & C inherits the properties of D.
I'm having three UIButton's for each child class. Each button in each sub class has some action. But the button's properties like color, frame, image are same in all three classes.
So, I need to do the following things for the buttons in each sub class's:
init the buttons
alloc them
set frame
set color
set action (using [button addTarget:self action:#selector(touchUpInsideAction:) forControlEvents:UIControlEventTouchUpInside])
etc
Except the "set action", everything is same in all child classes (Class A,B & C)
Now my question is, Can I create the button, its properties and action in Class D (Parent class) and Can I write the action method's (touchUpInsideAction:) implementation in each child class (Class A,B & C)?
So that, I can reduce my repeated code in my project. Here I'll call the child class's method touchUpInsideAction: from the parent class.
Is this right way or should I write button creation and properties for each Class separately?
Thanks in Advance

Create a class method in Class D. Set all button properties in that method.
Call class method from child class say A. Class method will return object of type UIButton.
Assign the selector and then add that object to the view.

As My Understanding D class should have button with setting all common property and action methods
. And Child class should be responsible to handle the Action if you want different functionality for every class.
Assume you have added target self and selector to button in supper class. you have created object of A, B or C. target for button in supper class(D) is self. Self is a representation of object So self will refer to objet of Class A, or B , or c.

Related

AS3 hitTest logic regarding instances of two different classes

I have instances of Class A and Class B and need help with the hitTest logic between the two on them.
When I drag an instance of Class B on stage I want any instances of Class A which will come on stage by AS3 will be automatically called by object instances of Class B for hitTestObject with A. I cannot create array (predefined & code compression) point.
I have already did this in past but forgot syntax arrangement.. but I am pretty clear how it was done.
Created class A
created method to let target this.
Created class B
import A
call method from A to find object
do hitTestObject
please help me out in the flow
Need this in ActionScript 3.0;

How to select a specific class from set of classes which are implementing same interface class?

How to select a specific class from set of classes which are implementing same interface class ?
You don't call a method directly from an interface, you call it on a reference that points to an instance of a class. Whichever class that is determines which method gets called.

Call (Report-)Function from Class Method to change screen title

I wanna change my titlebar in a dynpro when a specific class method is triggered. So I thought I could call a function in my report, where my dynpro is located, which changes uses the 'SET TITLE' to change the titlebar content.
Is this possible and how exactly? Or is there even a better way?
Thanks!
Use SET TITLEBAR during the PBO processing - it doesn't matter if it is used from a method, a FORM or the module directly. I'd recommend having one single SET TITLEBAR statement that is always called at the same point in the control flow instead of littering the code with SET TITLEBAR statements for better maintainability.
Recently I needed to implement something similar so I defined a class hierarchy where I created an abstract class with a method 'CALL_DYNPRO'. This method is intended to load an specific dynpro in the concrete classes.
So, depending on an action I defined internally I generate the appropriate instance and then the method 'CALL_DYNPRO' loads the dynpro I created with their own gui statuses and titles.
The following is more or less the code I created.
********************************* The abstract class
class lc_caller definition abstract.
public section.
methods: call_dynpro.
endclass.
class lc_caller implementation.
method call_dynpro.
endmethod.
endclass.
********************************* The concrete classes
class lc_caller_01 definition inheriting from lc_caller.
public section.
methods: call_dynpro redefinition.
endclass.
class lc_caller_01 implementation.
method call_dynpro.
call screen 101.
endmethod.
endclass.
class lc_caller_02 definition inheriting from lc_caller.
public section.
methods: call_dynpro redefinition.
endclass.
class lc_caller_02 implementation.
method call_dynpro.
call screen 102.
endmethod.
endclass.
********************************* Factory
class caller definition.
public section.
class-methods call importing i_type type char01
returning value(r_instance) type ref to lc_caller.
endclass.
class caller implementation.
method call.
data: caller1 type ref to lc_caller_01,
caller2 type ref to lc_caller_02.
case i_type.
when '0'.
create object caller1.
r_instance = caller1.
when '1'.
create object caller2.
r_instance = caller2.
when others.
endcase.
endmethod.
endclass.
start-of-selection.
data obj type ref to lc_caller.
obj = caller=>call( '0' ).
obj->call_dynpro( ).
This is the code inside the PBOs.
Dynpro 101
module status_0101 output.
set pf-status 'FORM1'.
set titlebar 'VER'.
endmodule.
Dynpro 102
module status_0102 output.
set pf-status 'FORM2'.
set titlebar 'TRA'.
endmodule.
If tomorrow I need to call another dynpro I create it and then code the concrete class to load it.
Very straightforward and works very nice.
Hope it helps.

How to call a method defined in one activity, from another

I'm having two activities, activity A and activity B.
I've defined a method in a class inside activity A.
Activity B has a class and its subclass.
Now I need to call the method from subclass.
As I cannot create the same method again within the subclass.
Declare your method as protected static. Then, from B, call it so: A.myMethod();

iphone, calling a method of different class in cocos2d layers?

I have two classes, both are subclasses of CCLayer,
I want to call a method of first class into second class, what should I code?
Your question is not providing much detail, but from my understanding of what you say, you need the following:
a selector in the public interface of your first class;
a pointer ivar in the second class that you will properly initialize so that it points to an instance of the first class;
In this way you will be able to call the first class' method from the second class.