2010-05-01 5 views
0

안녕하세요,문제 -> 이상한 CPButton 동작

나는 목적-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 
+0

XML 리더가 정수가 아닌 문자열을 생성하지 않습니까? 나는 XML 부분없이 버튼 코드를 테스트 할 것이다. –

+0

Thx, 방금 고쳤습니다 .... 당신 말이 맞아요. 문자열 값은 CGRectMake로 전달하기 전에 Number로 캐스팅되어야합니다. 혼란스러운 것은 단추가 제대로 그려지지만 마우스 이벤트 만 작동하지 않는다는 것입니다. – Superpro

답변

0

카푸치노가 무료로 당신이 대부분의 기능을 제공합니다.

CPURLConnection을 사용하여 파일을로드 할 수 있습니다.

Atlas (또는 Interface Builder 및 nib2cib)이 자동으로 cib 파일을 생성하므로 Cappuccino는 이미 cib 파일에서 UI를 작성하는 방법을 이미 알고 있습니다.

실제로이 작업을 수행하기 위해 자체 시스템을 구현하려는 경우로드하려는 실제 XML을 제공 할 수 있습니까? 또한 XML을 사용하지 않고 단추를로드 해보십시오. 예를 들어 :

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

+ buttonWithTitle:

자동으로 초기화 버튼을 - sizeToFit를 호출합니다, 그래서 당신은 당신의있는 contentView에 추가 할 수 있으며 적절한 크기로 볼 수 있어야합니다.