Wednesday, 15 May 2013

xcode - How to return type UILabel from a created method -



xcode - How to return type UILabel from a created method -

i have this

uilabel *selectedlabel; selectedlabel = nil; if (is_x) { selectedlabel = labelfield_x; } else if (is_y) { selectedlabel = labelfield_y; } else if (is_z) { selectedlabel = labelfield_z; }

to prevent repeating in code, how can create method homecoming type uilabel class.

i have tried (it does't work):

in header (.h) file:

//new method - (uilabel *) selected;

in implementation (.m) file:

- (uilabel *) selected { uilabel *selectedlabel; selectedlabel = nil; if (is_x) { selectedlabel = labelfield_x; } else if (is_y) { selectedlabel = labelfield_y; } else if (is_z) { selectedlabel = labelfield_z; } homecoming selectedlabel; } - (ibaction)buttonpressed:(id)sender{ [self selected]; }

how can homecoming selectedlabel within ibaction.

thank you.

your code looks right, need create uilabel variable in buttonpressed: method store reference returned label. alter

[self selected];

to:

uilabel *selectedlabel = [self selected]; // want selectedlabel

xcode xcode4 xcode4.5

No comments:

Post a Comment