1

Possible Duplicate:
C function calling objective C functions

I've done the following code in ViewController.m

-(void) callIncomingCreateButton
{

        UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

        //set the position of the button
        button.frame = CGRectMake(100, 170, 100, 30);

        //set the button's title
        [button setTitle:@"Click Me!" forState:UIControlStateNormal];

        //add the button to the view
        [self.view addSubview:button];
}

- (IBAction)DemoCall:(id)sender {

    callIncoming(1, "a");
}

int callIncoming(int a, char* b)
{
    ViewController * tempObj = [[ViewController alloc] init];
    [tempObj callIncomingCreateButton];

    return a;

}

But still the UIButton is not getting displayed, what am I missing here.

Edit : this is for iOS and yes, the function does get called. I put a breakpoint and stepped it through.

Community
  • 1
  • 1
anotherCoder
  • 712
  • 3
  • 11
  • 25

1 Answers1

0
ViewController * tempObj = [[ViewController alloc] init];
[tempObj callIncomingClass];

It's hard to tell from your example, but assuming that -callIncomingClass is actually part of the definition of ViewController and callIncoming() is called from somewhere else, a likely problem is that tempObj is not the current view controller. You'd need to push tempObj onto the navigation stack, present it modally, or otherwise make it the active view controller in order for its view to be loaded. If its view isn't loaded, then there's no view to add the button to, and even if it has a view, that view won't be in the window.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • Yes, this might be the case. Not entirely sure and hence not marking the answer. Let me check and and be sure about it. – anotherCoder Oct 12 '12 at 09:31