라이브러리

[PHP] UIControl::getParent - 부모 컨트롤 가져오기




UIControl::getParent

`UIControl::getParent` 메서드는 `UIControl` 클래스의 부모 컨트롤을 반환하는 메서드입니다. 이 메서드는 `UIControl` 인스턴스가 다른 컨트롤의 자식 인스턴스인 경우에만 사용할 수 있습니다.

예제

#hostingforum.kr
php

// 부모 컨트롤을 만들기 위해 UIView 클래스를 상속합니다.

class ParentView extends UIView {

    public function __construct() {

        parent::__construct();

        $this->backgroundColor = Color::WHITE;

    }

}



// 자식 컨트롤을 만들기 위해 UIControl 클래스를 상속합니다.

class ChildControl extends UIControl {

    public function __construct() {

        parent::__construct();

        $this->backgroundColor = Color::RED;

    }



    public function getParent() {

        return parent::getParent();

    }

}



// 부모 컨트롤을 생성합니다.

$parent = new ParentView();



// 자식 컨트롤을 생성합니다.

$child = new ChildControl();



// 자식 컨트롤의 부모 컨트롤을 반환합니다.

$parentControl = $child->getParent();



// 부모 컨트롤의 배경색을 변경합니다.

$parentControl->backgroundColor = Color::GREEN;



// 결과를 출력합니다.

echo "부모 컨트롤의 배경색: " . $parentControl->backgroundColor . "
";



결과

#hostingforum.kr


부모 컨트롤의 배경색: GREEN



예제 설명

이 예제에서는 `ParentView` 클래스를 만들고 `ChildControl` 클래스를 만들었습니다. `ChildControl` 클래스는 `UIControl` 클래스를 상속하고 `getParent` 메서드를 오버라이딩했습니다. `getParent` 메서드는 부모 컨트롤을 반환합니다.

`ParentView` 인스턴스를 생성하고 `ChildControl` 인스턴스를 생성했습니다. `ChildControl` 인스턴스의 `getParent` 메서드를 호출하여 부모 컨트롤을 반환했습니다. 부모 컨트롤의 배경색을 변경하고 결과를 출력했습니다.

주의

`UIControl::getParent` 메서드는 `UIControl` 인스턴스가 다른 컨트롤의 자식 인스턴스인 경우에만 사용할 수 있습니다. 만약 `UIControl` 인스턴스가 다른 컨트롤의 자식 인스턴스가 아닌 경우 `null`을 반환합니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 8,985건 / 66 페이지

검색

게시물 검색