Target C: UIButton not showing

Possible duplicate:
C function calling C objective functions

I made 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 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 UIButton does not display what I miss here.

Edit: this is for iOS and yes, the function calls. I set a breakpoint and went through it.

+1
source share
1 answer
 ViewController * tempObj = [[ViewController alloc] init]; [tempObj callIncomingClass]; 

It's hard to tell from your example, but assuming that -callIncomingClass is actually part of the ViewController definition and callIncoming() is being called from another place, the probable problem is that tempObj not the current view controller. You need to push tempObj on the navigation stack, present it as a modality, or otherwise make it the active view controller so that its view is loaded. If its view is not loaded, then there is no view to add a button, and even if it has a view, that view will not be in the window.

0
source

Source: https://habr.com/ru/post/1439316/


All Articles