LoginSignup
1
1

More than 5 years have passed since last update.

【Titanium】iOSモジュール内でのaddSubViewに関して

Last updated at Posted at 2015-08-13

モジュール内で作ったUIViewにaddSubViewをしようとしてハマったので共有メモ。
原因はProxy側でのメソッドの宣言方法にあった。

TiUIView側で以下のようなコードを書いたとする

HogeView.m
-(void)testMethod:(id)args{
    UILabel *label = [[UILabel alloc] init];
    label.text = @"Hello!";
    label.frame = CGRectMake(0, 0, 200, 200);
    label.backgroundColor = [UIColor blueColor];
    label.textColor = [UIColor whiteColor];
    label.textAlignment = UITextAlignmentCenter;

    [self addSubview:label];
}

このメソッドをJavaScript側から呼ぶためにProxyに宣言する。

HogeViewProxy.m
#import "HogeViewProxy.h"
@implementation HogeViewProxy

USE_VIEW_FOR_METHOD(void, testMethod, id);

@end

これ↑で、JavaScript側から呼んでも一切描画されない。正確にはaddはされているが描画されない。
いやぁ困った。本当に困った。

で、適当にGithubをあさってたら見つけた。解決策はProxy側でのメソッド宣言を変更する。

HogeViewProxy.m
#import "HogeViewProxy.h"
#import "HogeView.h"
#import "TiUtils.h"

@implementation HogeViewProxy

-(void)testMethod:(id)args
{
    TiThreadPerformOnMainThread(^{[(HogeView*)[self view] testMethod:args];}, NO);
}

@end

この書き方に変更後、JavaScript側から呼んだら描画された。

USE_VIEW_FOR_METHODじゃあダメなのね・・・って話。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1