Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8674047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:36:35+00:00 2026-06-12T19:36:35+00:00

I’ve a c function in my viewController.m. int abc(int a, char* b) { //do

  • 0

I’ve a c function in my viewController.m.

int abc(int a, char* b)
{
//do something
}

I also have a function

-(void) callIncomingClass
{
    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];
}

Now I want to call callIncomingClass from within the function abc now.

How do you suggest I go about it??

Why I want to call an Objective C method from the C function is, I’ve cannot create a button or do some processing like that in the C function.

Should the following code work :

int abc(int a, char* b)
{ 
    ViewController * tempObj = [[ViewController alloc] init];
    [tempObj callIncomingClass];
}

edit : the big picture of what I am doing
There is a c library, i.e. a library.c and library.h file. The library.h file has a struct that has callback functions. These need to be assigned with function pointers. so I’ve a c function with the signature int abc(int,char*) that is to be assigned to the callback function in the struct.

This function abc is defined in ViewController.m.
Ideally i wanted it to be defined in a separate file. but this is also okie.

So now, the callback event happens, I want to create a UIButton with some action on the View. As I can’t create a UIButton from a c function, i am calling a objective C method of the ViewController class, that creates the UIButton.

Hope that clears the picture as to how I am planning to use this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:36:36+00:00Added an answer on June 12, 2026 at 7:36 pm

    Your button doesn’t show because of what others and myself were saying: you need the existing instance of the ViewController. You are creating an entirely new instance of the ViewController, which is never brought on screen or pushed, etc.

    You can accomplish what you need to do by using a global variable that points to your existing instance.

    Here’s what your .m should look like:

    #import "ViewController.h"
    
    static ViewController *viewController = nil;
    
    @implementation ViewController
    
    - (id)init {
        if ((self = [super init])) {
             viewController = self;
        }
        return self;
    }
    
    - (void)dealloc {
        viewController = nil;
    }
    
    -(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");
    }
    
    @end
    
    int callIncoming(int a, char* b) {
        [viewController callIncomingCreateButton];
        return a;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
I have a small JavaScript validation script that validates inputs based on Regex. I
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.