I need to call a method that has been defined in the same class.I am calling the method initiateSession from the function A.
-(BOOL)intitiateSession
{
//stmts
return YES;
}
-(BOOL)A
{
if([self initiateSession])
{
//stmts
}
retur开发者_运维知识库n YES;
}
getting a runtime error as,
Terminating app due to uncaught exception
cannot init a class object
EDITED:
@implementation Data
-(BOOL)initiateSession
{
NSLog(@"I am into the initiateSession!!");
return YES;
}
-(BOOL)getNHPData{
NSLog(@"In getNHPData!!");
if([self initiateSession])
{
NSLog(@"I am into the session");
}
return YES;
}
@end
Here in the if loop i will call the function.Execute the function and if the function
executes to true i'm getting inside the scope.I could not able to call one function from
other function.
getNHPData()
is not an initializer and should not be calling [super init]
. That is something you would call from within your own initializer. Your code as written will not even compile (your @implementation
line is incorrect). You are certainly receiving many warnings in the above code that you should be listening to (you're returning self
from a BOOL method in one case, and have no return
in the other case). Your actual error suggests you're doing something like [Data getNHPData]
which is not legal since getNHPData
is an instance method. You should be getting warnings about that as well.
First, clean up all your warnings. That will probably get you moving in the right direction. Cocoadevcentral has a quick intro to all the issues you're running into.
You need to call [super init]
in your overwrite of -(id) init
.
See #3 and #6 here.
Always do a super init
call, when you override init
in your class.
精彩评论