How to call an Objective-C Method from a C Method?
2015-12-24 20:41
495 查看
I know your question is already answered by Aviad but just to add to the info since this is not unrelated:
In my case I needed to call an Objective-C method from a C function that I did not call myself (a Carbon Event function triggered by registering a global hotkey event) so passing self as a parameter was impossible. In this particular case you can do this:
Define a class variable in your implementation:
Then in your init method, set it to self:
You can then call Objective-C methods from any C function in the class without the need to pass
a parameter to the function:
转自:http://stackoverflow.com/questions/1280017/how-to-call-an-objective-c-method-from-a-c-method
In my case I needed to call an Objective-C method from a C function that I did not call myself (a Carbon Event function triggered by registering a global hotkey event) so passing self as a parameter was impossible. In this particular case you can do this:
Define a class variable in your implementation:
id thisClass;
Then in your init method, set it to self:
thisClass = self;
You can then call Objective-C methods from any C function in the class without the need to pass
selfas
a parameter to the function:
void cMethod([some parameters]) { [thisClass thisIsAnObjCMethod]; }
转自:http://stackoverflow.com/questions/1280017/how-to-call-an-objective-c-method-from-a-c-method
相关文章推荐
- Objective - C UITableView界面传值 从前往后,从后往前
- Objective - C UITableView学习笔记
- 【转】Android自动化测试(UiAutomator)——UiObject
- java线程同步:使用Object的wait,notify,notifyAll做线程调度
- Objective--C 导航视图控制器
- Objective-C基础1-类目(Category)和延展(Extension)的区别
- Objective-C 集合之NSArray的常用方法
- Objective-C NSObject 的实现分析(2014-10-23更新)
- Objective-C Runtime 总结:消息机制 篇
- Object.ReferenceEquals
- 遍历系统的所有ObjectType和TypeIndex
- iOS开发系列--Objective-C之KVC、KVO
- Objective-c语言_内存管理2(代码)
- Objective-C 和 Core Foundation 对象相互转换的内存管理总结
- Ubuntu snmpwalk 执行报错 “Unknown Object Identifier”
- ActiveX控件之ActiveXObject is not defined
- JSONObject、JSONArray
- Objective-C:Foundation框架-常用类-NSObject
- Objective-C:Foundation框架-常用类-NSDate
- Objective-C:Foundation框架-常用类-NSNull