0
我想做一个简单的例子,在ios中使用c.And我写了下面的代码来呈现一个view.It工作正常。但问题是,我想通过直接文本设置到其中的UILabel我创建了对象。如何在objc_msgSend()中传递直接字符串作为参数?
BOOL AppDel_didFinishLaunching(struct AppDel *self, SEL _cmd, void *application, void *options)
{
self->window = objc_msgSend(objc_getClass("UIWindow"), sel_getUid("alloc"));
self->window = objc_msgSend(self->window, sel_getUid("initWithFrame:"), (struct CGRect) { 0, 0, 320, 480 });
id viewController = objc_msgSend(objc_msgSend(objc_getClass("UIViewController"), sel_getUid("alloc")), sel_getUid("init"));
id view = objc_msgSend(objc_msgSend(objc_getClass("View"), sel_getUid("alloc")), sel_getUid("initWithFrame:"), (struct CGRect) { 0, 0, 320, 480 });
id label=objc_msgSend(objc_msgSend(objc_getClass("UILabel"), sel_getUid("alloc")), sel_getUid("initWithFrame:"),(struct CGRect){20,20,200,30});
objc_msgSend(label, sel_getUid("setBackgroundColor:"),objc_msgSend(objc_getClass("UIColor"), sel_getUid("greenColor")));
objc_msgSend(label, sel_getUid("setText:"),?); //here how to set text by direct string?
objc_msgSend(view, sel_getUid("addSubview:"),label);
objc_msgSend(objc_msgSend(viewController, sel_getUid("view")), sel_getUid("addSubview:"), view);
objc_msgSend(self->window, sel_getUid("setRootViewController:"), viewController);
objc_msgSend(self->window, sel_getUid("makeKeyAndVisible"));
return YES;
}
objc_msgSend(标签,sel_getUid( “的setText:”),?); //在这一行我必须传递字符串。
你有什么想法吗? 谢谢!
objc_msgSend(label,sel_getUid(“setText:”),@“yourstring”); – 2013-02-18 04:41:51
显示错误预期表达式 – Warewolf 2013-02-18 04:43:05
'NSString * str = @“yourstring”; objc_msgSend(label,sel_getUid(“setText:”),str);' – 2013-02-18 04:50:49