안녕하세요,문제 -> 이상한 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
XML 리더가 정수가 아닌 문자열을 생성하지 않습니까? 나는 XML 부분없이 버튼 코드를 테스트 할 것이다. –
Thx, 방금 고쳤습니다 .... 당신 말이 맞아요. 문자열 값은 CGRectMake로 전달하기 전에 Number로 캐스팅되어야합니다. 혼란스러운 것은 단추가 제대로 그려지지만 마우스 이벤트 만 작동하지 않는다는 것입니다. – Superpro