0

ハロー、

私はobjective-jとカプチーノが初めてで、xmlファイルから動的にGUIを作成する小さなアプリケーションを作成しようとしました。

残念ながら、部分的にしか機能しません。ボタン領域が乱れているようです。これは、ボタン以外をクリックすると、ボタンも反応することを意味します....

私を助けてください。理解できません..

- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{

    mControlList = [CPArray alloc];

   theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero()
    styleMask:CPBorderlessBridgeWindowMask],
    contentView = [theWindow contentView];
    [contentView setFrame:[[contentView superview] bounds]];
    [contentView setAutoresizingMask:CPViewWidthSizable |
CPViewHeightSizable];


    // Loadxmlfile
    var xhttp;
    if (window.XMLHttpRequest)
    {
        xhttp=new XMLHttpRequest()
    }
    else
    {
        xhttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    xhttp.open("GET","test.xml",false);
    xhttp.send("");
    xmlDoc = xhttp.responseXML;

    //Get controls nodeand iterate through all controls
    var node = xmlDoc.getElementsByTagName("controls")[0];
    for (var i=0; i<node.childNodes.length; i++) {
        if(node.childNodes[i].nodeName=="button"){
            var item = node.childNodes[i];

            var name = item.attributes["name"].nodeValue;
            var text = item.getElementsByTagName("text")
[0].childNodes[0].nodeValue;
            var x=      item.getElementsByTagName("rect")
[0].attributes["x"].nodeValue;
            var y=      item.getElementsByTagName("rect")
[0].attributes["y"].nodeValue;
            var width=  item.getElementsByTagName("rect")
[0].attributes["width"].nodeValue;
            var height= item.getElementsByTagName("rect")
[0].attributes["height"].nodeValue;

            var b = [[Button alloc] InitWithParent:contentView Text:text X:x
Y:y Width:width Height:height];
            [mControlList addObject:b];
        }
    }

    [theWindow orderFront:self];

}

@implementation Button : CPObject
{
    CPButton _button;
}

- (Button)InitWithParent:(CPView)contentView Text:(CPString)text X:
(int)x Y:(int)y Width:(int)width Height:(int)height
{
    _button = [[CPButton alloc] initWithFrame:
CGRectMake(x,y,width,height)];
    [_button setTitle:text];
    [_button setTarget:self];
    [_button setAction:@selector(cmdNext_onClick:)];
    [contentView addSubview:_button];
    return self;
}

- (void)cmdNext_onClick:(id)sender
{
}
@end
4

1 に答える 1

0

Cappuccino は、この機能のほとんどを無料で提供します。

CPURLConnectionを使用してファイルをロードできます。

また、 Atlas (またはInterface Builderと nib2cib) は自動的に cib ファイルを作成します。Cappuccino 自体は、cib ファイルから UI を構築する方法を既に知っています。

これを行うために独自のシステムを本当に実装したい場合は、ロードしようとしている実際の XML を提供していただけますか? また、XML を使用せずにボタンをロードしてみてください。例えば:

var myButton = [CPButton buttonWithTitle:@"My Cool Button"];
[contentView addSubview:myButton];

+ buttonWithTitle:初期化されたボタンで自動的に呼び出さ- sizeToFitれるため、それを contentView に追加するだけで、適切なサイズで表示されるはずです。

于 2010-05-10T09:54:05.500 に答える