Skip to content
9miao edited this page Sep 29, 2014 · 2 revisions

CAViewController

Class Description

CAViewController’s most basic function is to control view switching as CAView controller. View controller plays control layer (C) role in MVC design mode and CAViewController’s function is to manage related view as well as mutual communicate and coordinate with other CAViewController.

Base Class

CAResponder, CAViewDelegate, CAKeypadDelegate

Attribute

Access modifier

Attribute name

Description

protected

NavigationController

navigationController that is currently controlled by viewController

protected

tabBarController

tabBarController that is currently controlled by viewController

protected

NavigationBarItem

navigationBarItem properties

protected

TabBarItem

tabBarItem properties

Method

Access modifier

Method name

Description

protected

viewDidLoad

Auto trigger after root view of view controller loading

protected

viewDidUnload

Unload view controller’s view and its related objects

protected

reshapeViewRectDidFinish

monitor root view’s size

protected

getView

return root view of current view controller

public

getNibName

Obtain the type of current view controller

public

isKeypadEnabled

respond to keyboard event or not

public

setKeypadEnabled

set keyboard response event

public

keyBackCliched

respond to backspace key

public

keyMenuClicked

respond to Menu key

public

isViewRunning

judge current viewController’s root view is running or not

public

presentModalViewController

Pop up a new viewController in current viewController

public

dismissModalViewController

Hide the new viewController

Attribute Description

Title
Type: string
Descripiton: viewController’s title

NavigationController
Type: CANavigationController*
Descripiton: read-only property

tabBarController
Type: CATabBarController*
Descripiton: read-only property

NavigationBarItem
Type: CANavigationBarItem*
Descripiton: current viewController’s navigationBarItem, get/set{}.

TabBarItem
Type: CATabBarItem*
Descripiton: current viewController’s tabBarItem, get/set{}.

Method Description

virtual void viewDidLoad()=0
return value: void
Descripiton: It will be called after view loading completes, in this method we can futher initilize and customize view, but need to rewrite it.

Example:
void FirstViewController: : viewDidLoad()
{
CAImageView* imageView =
CAImageView: : createWithImage(CAImage: : create("9m. jpg"));
imageView->setFrame(CCRect(100, 100, 0, 0));
this->getView()->addSubview(imageView);

CALabel* ttf = CALabel: : createWithFrame(CCRect(200, 450, 0, 0));
ttf->setColor(ccc4(0,0,0,255));
ttf->setFontSize(50);
ttf->setText("Hello World!" );
ttf->setFontName("Arial");
this->getView()->addSubview(ttf);
}

virtual void viewDidUnload()=0
Return value: void
Descripiton: this interface will be called when system destorys current viewController, so as to release resource, but need to rewrite it.

virtual void reshapeViewRectDidFinish()
Return value: void
Descripiton: We can obtain root view’s new size by monitoring this interface if the size of root view of viewController changes.

CAView getView()*
Return value: CAView*
Descripiton: return root view’s object, viewController will build a view as root view by default.

const char getNibName()*
Return value: const char*
Descripiton: Obtain the type of current view controller

Example:
const char* CAViewController: : getNibName()
{
return typeid(*this). name();
}

virtual bool isKeypadEnabled()
Return value: bool
Descripiton: virtual function and return a bool value to judge responding to keyboard event or not.

virtual void setKeypadEnabled(bool value)
Return value: void
Parameter:

Type

Parameter name

Description

bool

value

respond to keyboard event flag bit

Descripiton: virtual function and transfer a bool value to judge responding to keyboard event or not.

Example:
void CAViewController: : setKeypadEnabled(bool enabled)
{
if (enabled ! = m_bKeypadEnabled)
{
m_bKeypadEnabled = enabled;

CCDirector* pDirector = CCDirector: : sharedDirector();
if (enabled)
{
pDirector->getKeypadDispatcher()->addDelegate(this);
}
else
{
pDirector->getKeypadDispatcher()->removeDelegate(this);
}
}
}

virtual void keyBackClicked()
Return value: void
Descripiton: interface that responds to backspace key operation of device

virtual void keyMenuClicked()
Return value: void
Descripiton: interface that responds to menu operation of device

bool isViewRunning()
Return value: bool
Descripiton: judge current viewController’s root view is running or not

void presentModalViewController(CAViewController controller, bool animated)*
Return value: void
Parameter:

Type

Parameter name

Description

CAViewController

controller

new viewController

bool

animated

play switch animation or not

Descripiton: pop up a new viewController from bottom to top on screen by default and cover on the original viewController.

void dismissModalViewController(bool animated)
Return value: void
Parameter:

Type

Parameter name

Description

bool

animated

play switch animation or not

Descripiton: Hide the new viewController.
Clone this wiki locally