【发布时间】:2014-03-03 18:19:00
【问题描述】:
如何从 c++ 类调用 Objective C 实例方法?在 TestApp.cpp 我想在 TestDelegate.mm 中调用 updateUI
TestDelegate.h
#include "cinder/app/CinderView.h"
#include "TestApp.h"
#import <Cocoa/Cocoa.h>
@interface TestDelegate : NSObject <NSApplicationDelegate>
{
IBOutlet CinderView *cinderView;
IBOutlet NSWindow *window;
TestApp *mApp;
}
@property (assign) IBOutlet NSWindow *window;
- (IBAction)subdivisionSliderChanged:(id)sender;
- (void)updateUI;
@end
TestDelegate.mm
#include "cinder/Cinder.h"
#import "TestDelegate.h"
@implementation TestDelegate
@synthesize window;
- (void)dealloc
{
[super dealloc];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
mApp = new TestApp;
mApp->prepareLaunch();
mApp->setupCinderView( cinderView, cinder::app::RendererGl::create() );
mApp->launch();
}
- (void)updateUI
{
//Set new values...
}
@end
TestApp.h
#pragma once
#include "cinder/app/AppCocoaView.h"
class TestApp : public cinder::app::AppCocoaView {
public:
void setup();
void draw();
};
TestApp.cpp
#include "TestApp.h"
#include "cinder/gl/gl.h"
using namespace ci;
using namespace ci::app;
void TestApp::setup()
{
//Set values
//Call updateUI method in TestDelegate.mm
}
void TestApp::draw()
{
}
【问题讨论】:
-
这不是重复的吗? stackoverflow.com/questions/6958685/… 一旦进入 .mm,所有 C++ 和 Obj-C 都可以正常工作。
标签: c++ objective-c objective-c++