0

I am trying to make a simple example using c in ios.And I have written following code to present a view.It is working fine.But the problem is that I want to pass direct text to set in to the UILabel of which I have created object.

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:"),?); //In this line i have to pass string.

have u any idea? Thanks!.

14
  • 1
    objc_msgSend(label, sel_getUid("setText:"),@"yourstring"); Commented Feb 18, 2013 at 4:41
  • showing error Expected Expression Commented Feb 18, 2013 at 4:43
  • NSString *str = @"yourstring"; objc_msgSend(label, sel_getUid("setText:"),str); Commented Feb 18, 2013 at 4:50
  • NSString *string = @"yourString"; objc_msgSend(label, sel_getUid("setText:"),string); Commented Feb 18, 2013 at 4:52
  • NSString not detecting Commented Feb 18, 2013 at 4:54

1 Answer 1

1
objc_msgSend(label, sel_getUid("setText:"),CFSTR("This is my string."));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.