gpt4 book ai didi

objective-c - c函数如何访问.mm中的objective-c属性

转载 作者:行者123 更新时间:2023-11-30 15:22:38 26 4
gpt4 key购买 nike

@property (nonatomic, strong) UILabel *versionLabel;

我尝试这样写:

void sipmessagecallback(char* pMsg)
{
printf("pMsg=%s\n", pMsg);
self.versionLabel.text = [NSString stringWithFormat:@"%s", pMsg];
}

error : Use of undeclared identifier 'self'

最佳答案

C 函数不是方法,因此无法直接访问您所在类的实例变量,包括 self。您可以编写一个 C 函数,其工作方式如下:

void sipmessagecallback(char *pMsg, MyClass *self) {
printf("pMsg=%s\n", pMsg);
self.versionLabel.text = [NSString stringWithFormat:@"%s", pMsg];
}

显然,当您调用此函数时,您需要将 self 传递给该函数。

关于objective-c - c函数如何访问.mm中的objective-c属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29166720/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com