Skip to Content
COCOA學習手冊--使用OBJECTIVE-C第三版
book

COCOA學習手冊--使用OBJECTIVE-C第三版

by Paris Buttfield-Addison, Jonathon Manning
June 2013
Intermediate to advanced
360 pages
6h 50m
Chinese
GoTop Information, Inc.
Content preview from COCOA學習手冊--使用OBJECTIVE-C第三版
第十章
Cocoa 繫結
目前為止,在這本書裡,我們已經詳細討論過模型—視圖—控制器的設計模式在 Cocoa
Cocoa Touch 裡如何運作,以及將應用程式的程式碼分成不同責任區域為何能夠產生
容易管理的程式碼基礎(codebase)。
然而,有時候,撰寫獨立的模型、視圖、及控制器看起來可能好像殺雞用牛刀,特別
是,當控制器需要做的事情只是從模型直接將資訊傳遞給視圖時(反之亦然)。在許多
情況中,你想要產生的行為只是用標籤展示儲存在模型物件裡的資訊。
為了解決這個問題,Apple 引進 OS X 裡的
繫結機制
bindings
)。繫結是視圖與物件之
間的連結,在當中,物件的內容被用來直接驅動視圖的展示內容。繫結意味著你能夠撰
寫較少的程式碼,並且完成同樣出色的功能。
在這一章裡,你將學習如何使用繫結機制,將你的介面直接連結到資料。你也會學到如
何使用 Apple 提供的內建控制器類別來管理物件群集(collection)。在本章結束時,你
將建構出精緻且引人注目的應用程式,同時撰寫最少量的程式碼。
繫結機制僅於 OS X 上有支援。iOS 開發者,抱歉啦﹗
把視圖和模型繫結起來
繫結只是讓你告訴視圖它的內容來自何處的一道指示,有點像是說,「好吧,文字欄
位,你要顯示的文字來自這邊這個物件,如果它發生改變,就更新你自己吧!同樣地,
當你發生改變時,請通知該物件更新它所儲存的文字。」
163
164
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

網頁互動式資料視覺化:使用D3

網頁互動式資料視覺化:使用D3

Scott Murray
深入淺出代數

深入淺出代數

Tracey Pilone, Dan Pilone
自然语言处理实战:从入门到项目实践

自然语言处理实战:从入门到项目实践

Sowmya Vajjala, Bodhisattwa Majumder, Anuj Gupta, Harshit Surana

Publisher Resources

ISBN: 9789862768136