【发布时间】:2013-11-18 12:28:00
【问题描述】:
我在 MyViewController.m 文件中有一个我无法修改的 API:
void my_Callback (void* context, xxxxxx::eventType::type eventtype, int code, const myconst)
{
//do stuff
}
我需要调用这个函数:
-(void) update
{
self.textbox.test =@"new text";
}
但是当我尝试这样做时
void my_Callback (void* context, xxxxxx::eventType::type eventtype, int code, const myconst)
{
//do stuff
[self update];
}
我收到错误,因为它无法重新识别“自我”。
我试过了:
ViewController *newview = [[Viewcontroller alloc]init];
void my_Callback (void* context, xxxxxx::eventType::type eventtype, int code, const myconst)
{
//do stuff
[newview update];
}
它最终进入了我的函数“更新”,但没有设置新的文本。
如何更新我的文本?谢谢
【问题讨论】:
-
您已将 self 作为参数传递。还要检查这个线程:stackoverflow.com/questions/1280017/…
-
当您尝试创建新的视图控制器时,文本没有得到更新,因为您正在更新的 textView 是 self.textbox.text 并且您正在为新的视图控制器调用更新函数。关于你得到的无法识别“自我”错误,可能是因为它是一个静态方法。
-
"my_Callback" 是一个常规的 C 方法,与包含它的 .m 文件中的其他函数没有逻辑关联。如果您想要一个指向任何 Objective-C 对象(包括“self”)的指针,您必须将指针作为参数传递或以某种方式将其作为全局值访问。
标签: ios objective-c uiviewcontroller void self