xcode - Objective C - Get a class to return a value -
i ask questions, 1 frustrating me can not find answer anywhere!
i need call function in gamechallenges.m , return value view controller. gamechallenges.m called different view controllers, thats why separate. please help!
i have separate class file called gamechallenges.
this has function/method in it: in .h
@class statsviewcontroller; @interface gamechallenges : nsobject { statsviewcontroller* statscontroller; nsstring* challengetitle; } @property (nonatomic, retain) iboutlet statsviewcontroller* statscontroller; @property (assign) nsstring* challengetitle; -(nsstring*)checkchallenge:(int)challegeid; @end
in .m
#import "gamechallenges.h" #import "statsviewcontroller.h" @implementation gamechallenges @synthesize challengetitle,statscontroller; -(nsstring*)checkchallenge:(int)challegeid{ if(challegeid==1){ self.challengetitle = @"some text."; return challengetitle; }else if(challegeid==2){ self.challengetitle = @"some other text."; return challengetitle; } }
from view controller called statsviewcontroller calling method
in .h
@class gamechallenges; @interface statsviewcontroller : uiviewcontroller { uilabel* challengeiddesctext; } @property (nonatomic, retain) iboutlet uilabel* challengeiddesctext; @property (nonatomic, retain) iboutlet gamechallenges* challenges; @end
in .m
[challenges checkchallenge:tempstring]; challengeiddesctext.text = challenges.challengetitle;
your code quite weird, i'd what's happening:
-[gamechallenges checkchallenge]
seems expect int
, call variable called tempstring
guess nsstring *
. more not, method ending without assigning challengetitle
, without valid return
value. fix return nil
last statement , passing int
.
this kind of problems easy solve using debugger.
also, have apple samples.
Comments
Post a Comment