-2

我在我的 UIViewController 中使用了这个函数

void showMap()
{

}

如果我使用objective-c 函数,我可以调用self.view,但是如何在UIViewContoller 内的C 函数中调用它?

(我需要self.view = myObject在 C 函数内部使用,当我尝试使用self.view = myObjectxcode 时说没有变量self

更新:

我需要这个在 Unity 3d 中使用

4

2 回答 2

2
    In . m file 

    for example  In LoginPage.m


    #import "LoginPage.h"

    LoginPage *loginP;

    @interface LoginPage ()

    @end

    @implementation LoginPage


    - (void)viewDidLoad
    {
        [super viewDidLoad];

        self.title=@"Login";
        self.navigationController.navigationBar.tintColor = [UIColor blackColor];

        loginP = self;  //assign self to loginP 
    }

    void showMap()
    {

    UIView *view = [[UIView alloc ]initWithFrame:CGRectMake(0, 10, 50, 100)];
        [loginP.view addSubview:view];  


//Now you can use self inside c function ..and access any method of class 

    }
于 2013-09-12T11:59:56.320 回答
0

我找到了解决方案

void showMap(UIViewController *self)
{
    self.view = newView;
}
于 2013-09-12T12:05:46.687 回答