iPhone – Add and Remove Subviews

The layout of an UIView in iPhone Application can be created and modified either by the Interface Builder or by code. If you make it by Interface Builder, you have to wire the items u created to File Owner.

On the other hand, u can make an Item on the UIView by code. The following example will created a “Hello World” UILabel at coordinate (10, 15) with size equals to 40 x 20;

// Create the UILabel instance
UILabel *aLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, 40, 20)];
// Set the tag of aLabel
aLabel.tag = 1;
// Set the text
aLabel.text = @"Hello World";
// Add the UILabel view to UIView associated with the controller
[self.view addSubview:aLabel];
// Release the memory
[aLabel release];

 

You can add different items such as UIImageView, UITextField etc. Please note that the view tag is the only field to distinguish different subviews.

To remove all the subviews except the one with tag equals to 1, you can use

for (UIView *subview in [self.view subviews]) {
	// Only remove the subviews with tag not equal to 1
	if (subview.tag != 1) {
		[subview removeFromSuperview];
	}
}

 

Done =)

Update @ 2011-06-18: Added the “Release the memory” code. Thanks Luke. =)

iPhone – Accessing the Global Variables in the AppDelegate

Sometimes u would need to create some Global Variables in an iPhone Application such that they can be accessed in other implementation class files.

Those Global Variables are created in the AppDelegate. If you want to access it in another file, you have to get the AppDelegate instance before you can read or write the Global Variables. For example, the HelloAppDelegate has a NSString instance variable named as greeting and i want to read it in the HelloViewController.m
Continue reading iPhone – Accessing the Global Variables in the AppDelegate

2008 Italy and Greece Journey Review @ 15

This slideshow requires JavaScript.

最後一站 Vatican

離開 Athens 返回 Rome,好彩 Alitalia 航空的財政危機還未使到飛機停飛,我和 Tinyan 先可以再次回到 Rome

係酒店安頓後就即刻出發到今次旅程的第三個國家 — Vatican

Vatican 係全世界最細的國家,但每日都有好多人來到這個進出都不需要出入境的國家。來到當然要去看著名的 St. Peter’s Basilica。裡面有一個聖彼得象,由於很多人會摸祂的右腳腳趾公,結果那腳趾公都被摸到失去了腳趾公的形狀。
Continue reading 2008 Italy and Greece Journey Review @ 15

2008 Italy and Greece Journey Review @ 14

This slideshow requires JavaScript.

第十站,再遊 Athens

係船上睡了一晚,天未光就回到 Piraeus,先到旅館放底行李,立即出發到雅典衛城 – Acropolis。早期的雅典衛城建於公元前6世紀,那時有一座雅典娜的神殿,現在叫做 Old Temple of Athena。之後衛城係公元前5世紀被波斯人破壞(第一次的希臘與波斯之戰)。係戰爭結束後,由雅典執行官 Pericles 帶領雅典人重建衛城,而擔起重建重任的有雕刻建築家 IctinusCallicrates

Propylaea

雅典衛城聖域的入口,由公元前437年開始建造,但到了公元前432年還未完成就停工。

 

Temple of Athena Nike

原先在此的神殿被波斯人破壞,直到公元前428年重建來紀念波斯戰爭獲勝,成為 Temple of Athena Nike。Nike 係勝利女神,雅典人曾經在神殿內放置沒有翅膀的 Nike 神象,象徵勝利女神永遠留在 Athens。

 

Sanctuary of Artemis Brauronia

位於 Parthenon 神殿前面,係祭祀代表月亮與狩獵女神 Artemis 的聖地,現在只剩下大理石碎片。

 

Old Temple of Athena

位於 Erechtheion 神殿旁邊,雅典衛城最早的神殿,被波斯人破壞,與 Sanctuary of Artemis Brauronia 一樣,只有大理石碎片。

 
Continue reading 2008 Italy and Greece Journey Review @ 14

2008 Italy and Greece Journey Review @ 13

This slideshow requires JavaScript.

繼續 Santorini

Day 3

Santorini 其實係愛琴海歷史悠久的小島,是公元前16世紀 Minoan civilization (米諾斯文明)的中心,但這個文明係公元前15世紀被 Nea Kameni 的超級火山爆發 (Minoan eruption) 所摧毀,直至到1967年,考古學家係 Santorini 南面的 Akrotiri 才將這個被埋在火山灰下3500年古代都市重現人間,據說這古代文明就是失落了的夢幻國度 — Atlantis

去到 Akrotiri 先知道這遺跡正在維修中 =.=,白行一趟,之後就返回 Fira,還好今日看到 Santorini 的日落。

今晚就會坐通宵船返 Athens,愛琴海,我一定會再來!!
Continue reading 2008 Italy and Greece Journey Review @ 13

2008 Italy and Greece Journey Review @ 12

This slideshow requires JavaScript.

繼續 Santorini

Day 2

我地的房間面向東方,所以天未光就起身睇日出。之後就到 Fira 閒逛,遊覽這個 Santorini 的主要城鎮。

Santorini 最特別的地方就是建於懸崖上的小屋,而 Fira 就有樓梯走到懸崖下的小碼頭,有些遊客會選擇坐纜車,有些會騎驢子,我地就選擇徒步,沿路都看到很多辛勤工作的驢子,仲有很多”地雷”。

下午就係 Fira 坐巴士到 Ia,坦白講,IaFira 更美,可惜天公不造美,看不到這裡的日落,唯有多拍幾幅夜景補償。
Continue reading 2008 Italy and Greece Journey Review @ 12

2008 Italy and Greece Journey Review @ 11

This slideshow requires JavaScript.

第九站 Santorini

去完 Delos,下午就離開 Mykonos 出發到另一個愛琴海小島 — Santorini

由於我們乘坐的船遲了開出,所以到達 Santorini 的時候已經係黃昏,旅館的老闆在碼頭等了我們差不多個多小時,真的有點不好意思。Santorini 的碼頭(舊碼頭)在懸崖下,如果沒有專車接送的話就只有第巴士,徒步是不可能的,可以的話記住要問清楚到達旅館的方法,當然最好他們有接送服務啦。

我地住的地方叫 Manos Villa,老闆娘別叫 Poppy,地點並不在市中心 Fira,所以比較便宜,如果要到市中心就要坐巴士,大概半小時一班車,10分鐘就到達 Fira,係 Santorini 記住要拍底巴士的更表,因為它是主要的交通公具。 PoppyPoppy 老公都好好人,check-in 時仲請我們飲 Santorini 出產的紅酒,結果我同 Tinyan 都買了一支做手信。
Continue reading 2008 Italy and Greece Journey Review @ 11

Dream BIG and go for it =)