iOS objc_msgSend报错问题

选中项目 - Project - Build Settings - Enable Strict Checking of objc_msgSend Calls 将其设置为 NO 即可

使用objc_msgSend创建视图:

  //案例一
 ZWMethodLearn *learn = ((ZWMethodLearn * (*)(id,  SEL))objc_msgSend)((id)[ZWMethodLearn class],  @selector(alloc));

    // 2.初始化对象
    learn = ((ZWMethodLearn * (*)(id, SEL))objc_msgSend)((id)learn, @selector(init));

    objc_msgSend(learn,@selector(getMethods));

***************************************************************
    //案例二
     ZWMethodLearn *lean =objc_msgSend([ZWMethodLearn class], @selector(alloc));
     objc_msgSend(lean, @selector(init));
     objc_msgSend(lean, @selector(getMethods));

     objc_msgSend(self.view, @selector(setBackgroundColor:),[UIColor redColor]);

    //创建视图
    UILabel *label=objc_msgSend([UILabel class], @selector(alloc));
    objc_msgSend(label, @selector(init));
    objc_msgSend(label, @selector(setFrame:),CGRectMake(20, 20, 200, 40));
    objc_msgSend(label, @selector(setBackgroundColor:),[UIColor greenColor]);
    objc_msgSend(label, @selector(setText:),@"恍恍惚惚");

    objc_msgSend(self.view, @selector(addSubview:),label);

你可能感兴趣的:(objc-msgSe)