yue1liang1chuan 2013-02-18 05:38 采纳率: 0%
浏览 2601

直接字符串作为参数传递

objc_msgSend()字符串作为参数传递。

想要做一个ios中使用C的例子,现在写了显示视图的代码,其他的运行正确,但是不知道怎么传递直接文本到UILabelUILable已经创建了对象。

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(label, sel_getUid("setText:"),?); //这行传递字符串

  • 写回答

1条回答 默认 最新

  • 睡觉不盖被 2015-08-25 03:43
    关注

    楼主 这是什么写法,通过xcode 中的C级 api 来生成界面 么

    评论

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?