[iOS基礎控制項,ios基礎控制項
A.需要掌握的1.基本屬性和方法
- 設定UITableView的dataSource、delegate
- UITableView多組資料和單組資料的展示
- UITableViewCell的常見屬性
- UITableView的效能最佳化(cell的迴圈利用)
- 自訂cell
2.UITableView的概念UITableView就是表格式資料UITableView繼承自UIScrollView,支援垂直滾動,而且效能好 3.UITableView的兩種樣式
- UITableViewStylePlain
- UITableViewStyleGrouped
4.展示資料
- UITableView需要一個資料來源dataSource來顯示資料
- UITableView向資料來源查詢一共有多少行資料和每一行的顯示內容
- 沒有資料來源的UITableView只是個空殼
- 凡是遵守了UITableViewDataSource協議的OC對象,都可以是UITableView的資料來源
5.UITableView和資料來源
1 // 資料總組數2 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; // Default is 1 if not implemented3 4 // 每組資料的行數5 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;6 7 // 每一行顯示的內容8 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
資料來源引用:
1 // 資料來源2 @property(nonatomic, assign) id<UITableViewDataSource> dataSource;
6.UITableView展示資料的過程(1)得到資料的組數
1 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
(2)得到每組資料的行數
1 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
(3)得到每行資料的內容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
7.解析.plist檔案,將資料群組中的每個Dictionary用Model封裝起來儲存 8.使用MVC模式M: ModelV: ViewC: Control 9.Cell簡介 10.UITableViewCell的contentView 11.UITableViewCell的結構 12.Cell重用原理 為了應對大量資料的載入和顯示,不必建立相同數量的Cell,只需要把當前需要顯示的資料載入到cell上就行了。 原理:滾動列表,移出視窗的UITableViewCell會被放入到一個對象池中,當有資料需要顯示的時候,就會從對象池中取出可用的UITableViewCell,然後載入資料顯示。 13.自訂的cell重用 有時候為了特定的需求,需要自訂繼承自UITableViewCell的類,可能一個UITableView中存在多種cell,會造成對象池中cell類型的混亂。 解決:利用UITableViewCell的 NSSting *reuseIdentifier 屬性,初始化cell的時候指定reuseIdentifier,這樣在對象池取出cell對象的時候要先通過這個字串標識檢查,如果不存在就是使用傳入的字串標識初始化一個cell對象。 14.cell重用代碼