I've a C file and a Objective C file.
Namely, C file being : CB.m
and CB.h
CB.m
contains a c function : callIncomings()
. This function has to be a C function because, it is a callback function. (Its signature cannot be changed)
the Objective C files are, ViewController.h/.xib/.m
and IncomingCall.h/.m/.xib
.
Now, I've declared the following in ViewController.h
static ViewController* varViewController;
in viewDidLoad
, I assign :
varViewController = self;
and I've the following code in CB.m
#include <stdio.h>
#import "ViewController.h"
#import "IncomingCall.h"
int callIncomings(int a, char* b)
{
IncomingCall *obj = [[IncomingCall alloc]initWithNibName:@"IncomingCall" bundle:nil];
//NSString *temp =
//NSString* string =
obj.tempAddress = [NSString stringWithFormat:@"%s" , b];
[obj setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[varViewController presentModalViewController:obj animated:YES];
[obj release];
return 1;
}
This function is called in :
- (IBAction)DemoCall:(id)sender {
callIncomings(1, "from C file");
}
The project builds fine, but the view IncomingCall()
is not getting displayed.
any ideas why??
EDIT : Also, I wanted to know, if I wanted to generalise the C function and load some different view say ABCD.view or IncomingCall view, how can I generalise this function.
EDIT 2 : This question can be a continuity from here : C function calling objective C functions
Some Clarifications :
When I put the callIncoming function in the viewcontroller.m file, it worked fine. But now I want to place it separately, in another file and hence the CB.m file.
So that answers your doubt about varViewController. The DemoCall function is in the ViewController file, if you notice its a IBAction, so yes, the function IncomingCall is definitely getting called.
Inputs : Yes, like someone pointed out, its true, the varViewController seems to be NULL. Now what??!! Where am I going wrong?? .