iOS Module: Access images from Resources folder

You must Login before you can answer or comment on any questions.

Hello,

I've been trying to figure this one out, but simply can't.

My code is something like this:

//Code 1
-(UIView*)square
{
    if (square==nil)
    {
        square = [[UIView alloc] initWithFrame:[self frame]];
        [self addSubview:square];
    }
    return square;
}
Pretty straight forward (right from the modules example).

However, one thing I'm not being able to figure out is how to add this:

//Code 2
square.backgroundColor = [[TiUtils colorValue:color] _color]
wherein I wish to obtain color from arguments passed to the TiUIViewProxy when initializing it in my js code as follows:
win.add(module.createView({
    width: Ti.UI.FILL,
    height: Ti.UI.FILL,
    color: 'black'
}));
Now, if I set this up by using the setter methods, it works perfectly fine. However, I would like to write Code 2 within Code 1, due to certain restrictions I cannot talk about. So, anyway to access the value for the key 'color' from within Code 1?

— asked 8 months ago by Nikhil Nigade
2 Comments
  • Oh dear me, sorry for the incorrect and mis-leading title for the question. My bad.

    — commented 8 months ago by Nikhil Nigade

  • I tried doing this:

    square.backgroundColor = [[TiUtils colorValue:[self valueForUndefinedKey: @"color"] _color]
    But it gives me the following error:
    [valueForUndefinedKey:]: this class is not the key value coding-compliant for the key color at app.js (line 21)
     
    // Line 21 of my app.js
     
    win.open();

    — commented 8 months ago by Nikhil Nigade

2 Answers

Accepted Answer

Hi Nikhil, i don't get the exact problem. but i think module development at wiki is giving good explanation.

How ever if you want to set the color within the initialization code i.e. is your code 1, then you have to call your initialization function from any of the life cycle method. methods like

-(void)frameSizeChanged:(CGRect)frame bounds:(CGRect)bounds
{
  if(square==nil){
[TiUtils setView:[self square] positionRect:bounds];
}
  if (square!=nil)
  {
    [TiUtils setView:square positionRect:bounds];
  }
}
of TiUiView class or any other TiUIViewProxy class life cycle method and you can set the color in the code 1 also.

— answered 8 months ago by Ashish Nigam
answer permalink
4 Comments
  • Hello Ashish,

    Well, what I'm having trouble with, is accessing the parameters passed from the js code to the UIView. So say I have a property, 'venue', set with a value in my js code.

    How do I access venue in the initialization block? [self valueForUndefinedKey: @'venue'] doesn't seem to work. Neither does [self valueForKey: @'venue'].

    — commented 8 months ago by Nikhil Nigade

  • Override the life cycle method in your TiViewProxy

    -(void)_initWithProperties:(NSDictionary*)properties{
    }
    here you will get all the properties and you can call the view square method over main thread from view proxy and from inside this method also. So change your view square method to receive some parameter like
    -(UIView*)square:(id)args
    {
    // get the args here which you need at the time of initialization.
        if (square==nil)
        {
            square = [[UIView alloc] initWithFrame:[self frame]];
            [self addSubview:square];
        }
        return square;
    }
    that will be a solution.

    other could be like declare venue as a property and write its setter in the view class with **_** symbol. as explained in the link.

    — commented 8 months ago by Ashish Nigam

  • Bingo! Solved my problem. Thank you very much Ashish.

    — commented 8 months ago by Nikhil Nigade

  • Show 1 more comment

IOS Objective-C code

-(void)useDocumentOpener:(id)args
{
    ENSURE_UI_THREAD_1_ARG(args);
    ENSURE_SINGLE_ARG_OR_NIL(args,NSDictionary);
    NSString *fileName = [TiUtils stringValue:@"path" properties:args ];    
    ....
}
in my javascript file
ciDocOpener.useDocumentOpener({
    path : tempFile.nativePath
});

Your Answer

Think you can help? Login to answer this question!