自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iOS可折疊的tableView的簡單實現(xiàn)

移動開發(fā) iOS
漫漫編程路,剛接觸iOS編程的你做好準備了么。凡事從無到有,由簡至繁,需要努力和堅韌,那么從最簡單的積累開始吧。

這里所說的 tableView 折疊,是借助 insert (insertRowsAtIndexPaths:withRowAnimation:) 和 delete (deleteRowsAtIndexPaths:withRowAnimation:) 對tableView 的 section 進行折疊,效果簡單。

我是初學(xué)者,還請各位看官指教。

搞這個東西,斷斷續(xù)續(xù)了幾天,現(xiàn)在終于可以告一段落了,雖然離可重用還有距離,但是我想以經(jīng)不遠了。

遇到的幾個問題:

1.NSMutableDictionary

NSMutableDictionary 內(nèi)的順序并不是執(zhí)行 setObjectForKey 的順序,順序是亂的(目測是亂的,不知道是不是有什么規(guī)律,請指教)。

我在這個東西上繞了一個大圈子。后來在 AppCode  下面調(diào)試,才發(fā)現(xiàn)這個問題。為保持插入順序,不得不換成兩個 NSMutableArray ,一個存 Key,一個存 Value.

2.headerViewForSection

我想在 numberOfRowsInSection 方法內(nèi)獲取該 section 的 header View ,然后讀取自定義的數(shù)據(jù),比如當(dāng)前狀態(tài)是否是折疊等。

查了一下API,發(fā)現(xiàn)有個 headerViewForSection 方法,但是無論如何,它的值一直都是nil,搞不明白。stackoverflow 上有說須要在使用之前用 tableView 的 registerNib:forHeaderFooterViewReuseIdentifier:  或 registerClass:forHeaderFooterViewReuseIdentifier:  方 法,我試了,沒用。

3.insertRowsAtIndexPaths 和 deleteRowsAtIndexPaths 同 numberOfRowsInSection 的關(guān)系

如果不處理好這個關(guān)系,大概所有的問題都是這樣的:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 6. The number of rows contained in an existing section after the update (0) must be equal to the number of rows contained in that section before the update (9), plus or minus the number of rows inserted or deleted from that section (0 inserted, 3 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 2 from section 4 which only contains 0 rows before the update'

大楖是說,numberOfRowsInSection 返回的數(shù)字和 insert / delete 后,section 所包含的行數(shù)不一致。

在 tableView 的 endUpdates 方法之前,應(yīng)該對標志變量做處理。endUpdates 后,會重新刷新 tableView ,numberOfRowsInSection 會重新被調(diào)用。

不理想的地方(壞代碼)

同上面講的1和2 ,由于 NSMutableDictionary 的無順序,我將 MutableDictionary 換成了 MutableArray 。

由于無法獲取指定 section 的 headerView ,所以,我只能將以經(jīng)生成的 headerView 記錄到某個 MutableArray 內(nèi),以供使用。

用 xib 設(shè)計自定義的 UIView

在新建 Objective-C Class 的時候,只有基類是 UIViewController 的,才能選“With XIB for user interface” 這個選項。

如果我想自定義一個 UIView , 這個 view 內(nèi)的控件很多,想想就是一件可怕的事情。還好,可以單獨新建一個 xib 文件。

a, 拖一個UIView 到 xib 編輯器中,然后更發(fā)這個 view 的size 為 Freeform, 這個 view 就可以自由的改變大小了。

b,更改 class 為自定義的 UIView 

c, File's Owner 的 class 還是 NSObject ,不要改。

d, 如何使用這個自定義的 UIView ?

***,上個效果圖吧

責(zé)任編輯:閆佳明 來源: cnblogs
相關(guān)推薦

2018-04-26 10:43:28

2021-12-01 17:42:42

微信macOS騰訊

2019-03-20 14:26:56

蘋果折疊屏iPhone X Fo

2022-03-02 09:53:51

微軟FlutterEngine PR

2015-12-29 10:20:40

谷歌眼鏡企業(yè)

2019-03-15 16:18:41

谷歌可折疊手機

2022-12-29 08:16:46

2019-05-08 15:21:30

谷歌折疊屏智能手機

2019-10-12 17:19:12

WindowsWindows 7Windows 10

2021-08-15 22:58:43

手機折疊手機三星

2022-07-12 06:05:27

NutUI折疊面板組件開發(fā)

2014-03-12 10:19:54

iOS對象

2014-03-12 10:13:00

iOSSEL對象

2013-06-14 13:50:28

iOS開發(fā)移動開發(fā)警告視圖

2013-07-05 10:26:40

Android
點贊
收藏

51CTO技術(shù)棧公眾號