iOS UITableview preference

新手哈,第一次寫技術(shù)文章饭尝,希望各位看官多多指教。

Table views can have one of two styles,UITableViewStylePlainandUITableViewStyleGrouped. When you create aUITableViewinstance you must specify a table style, and this style cannot be changed. In the plain style, section headers and footers float above the content if the part of a complete section is visible. A table view can have an index that appears as a bar on the right hand side of the table (for example, "A" through "Z"). You can touch a particular label to jump to the target section. The grouped style of table view provides a default background color and a default background view for all cells. The background view provides a visual grouping for all cells in a particular section. For example, one group could be a person's name and title, another group for phone numbers that the person uses, and another group for email accounts and so on. See the Settings application for examples of grouped tables. Table views in the grouped style cannot have an index.

很顯然献宫,這是tableview的兩種形式(基本都知道)钥平,大部分用的是plain,這個(gè)時(shí)候的section的header是浮在上面的姊途,滑動(dòng)的時(shí)候在頂部是固定的涉瘾,當(dāng)然,這個(gè)時(shí)候也可以添加個(gè)所以列表吭净,類似于通訊錄的26個(gè)字母的索引睡汹。當(dāng)然,有時(shí)候也用到group寂殉,一般在設(shè)置里用的比較多囚巴,這個(gè)時(shí)候就沒有索引了。

When sent asetEditing:animated:message (with a first parameter ofYES), the table view enters into editing mode where it shows the editing or reordering controls of each visible row, depending on theeditingStyleof each associatedUITableViewCell. Clicking on the insertion or deletion control causes the data source to receive atableView:commitEditingStyle:forRowAtIndexPath:message. You commit a deletion or insertion by callingdeleteRowsAtIndexPaths:withRowAnimation:orinsertRowsAtIndexPaths:withRowAnimation:, as appropriate. Also in editing mode, if a table-view cell has itsshowsReorderControlproperty set toYES, the data source receives atableView:moveRowAtIndexPath:toIndexPath:message. The data source can selectively remove the reordering control for cells by implementingtableView:canMoveRowAtIndexPath:.

這個(gè)是tableview的編輯模式友扰,可以是刪除彤叉,也可以是添加。

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{

return UITableViewCellEditingStyleInsert;

}

用這個(gè)去選擇你要的是刪除還是添加村怪。

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{


}

在這個(gè)回調(diào)里去添加你所希望發(fā)生的事件秽浇,當(dāng)用刪除的時(shí)候,可以用:

[tableView selectRowAtIndexPath:<#(nullable NSIndexPath *)#> animated:<#(BOOL)#> scrollPosition:<#(UITableViewScrollPosition)#>]

選擇你所需要?jiǎng)h除的indepath甚负,當(dāng)然柬焕,于此同時(shí),你要對(duì)數(shù)據(jù)源的數(shù)組進(jìn)行處理梭域,不然會(huì)蹦的思密達(dá)~

同理斑举,要添加也是一樣的:

[tableView insertSections:<#(nonnull NSIndexSet *)#> withRowAnimation:<#(UITableViewRowAnimation)#>]

當(dāng)然,很多同學(xué)剛剛接觸的時(shí)候病涨,會(huì)發(fā)現(xiàn)即使你只是設(shè)置了十個(gè)row富玷,但是下面的橫線密密麻麻的。既穆。赎懦。很多。有個(gè)小技巧就是你可以這樣設(shè)置:

_tableView.tableFooterView = [[UIView alloc] init];

當(dāng)然幻工,更多時(shí)候我們做的是對(duì)于datesource的處理励两,一般都是reloaddata。

這邊有一個(gè)小小的demo囊颅,用于tableview的movers

https://github.com/ioscick/LongpressTableViewCellDemo

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末伐蒋,一起剝皮案震驚了整個(gè)濱河市工三,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌先鱼,老刑警劉巖俭正,帶你破解...
    沈念sama閱讀 219,589評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異焙畔,居然都是意外死亡掸读,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,615評(píng)論 3 396
  • 文/潘曉璐 我一進(jìn)店門宏多,熙熙樓的掌柜王于貴愁眉苦臉地迎上來儿惫,“玉大人,你說我怎么就攤上這事伸但∩銮耄” “怎么了?”我有些...
    開封第一講書人閱讀 165,933評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵更胖,是天一觀的道長(zhǎng)铛铁。 經(jīng)常有香客問我,道長(zhǎng)却妨,這世上最難降的妖魔是什么饵逐? 我笑而不...
    開封第一講書人閱讀 58,976評(píng)論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮彪标,結(jié)果婚禮上倍权,老公的妹妹穿的比我還像新娘。我一直安慰自己捞烟,他們只是感情好薄声,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,999評(píng)論 6 393
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著题画,像睡著了一般默辨。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上婴程,一...
    開封第一講書人閱讀 51,775評(píng)論 1 307
  • 那天,我揣著相機(jī)與錄音抱婉,去河邊找鬼档叔。 笑死,一個(gè)胖子當(dāng)著我的面吹牛蒸绩,可吹牛的內(nèi)容都是我干的衙四。 我是一名探鬼主播,決...
    沈念sama閱讀 40,474評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼患亿,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼传蹈!你這毒婦竟也來了押逼?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,359評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤惦界,失蹤者是張志新(化名)和其女友劉穎挑格,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體沾歪,經(jīng)...
    沈念sama閱讀 45,854評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡漂彤,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,007評(píng)論 3 338
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了灾搏。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片挫望。...
    茶點(diǎn)故事閱讀 40,146評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖狂窑,靈堂內(nèi)的尸體忽然破棺而出媳板,到底是詐尸還是另有隱情,我是刑警寧澤泉哈,帶...
    沈念sama閱讀 35,826評(píng)論 5 346
  • 正文 年R本政府宣布蛉幸,位于F島的核電站,受9級(jí)特大地震影響旨巷,放射性物質(zhì)發(fā)生泄漏巨缘。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,484評(píng)論 3 331
  • 文/蒙蒙 一采呐、第九天 我趴在偏房一處隱蔽的房頂上張望若锁。 院中可真熱鬧,春花似錦斧吐、人聲如沸又固。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,029評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)仰冠。三九已至,卻和暖如春蝶糯,著一層夾襖步出監(jiān)牢的瞬間洋只,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,153評(píng)論 1 272
  • 我被黑心中介騙來泰國(guó)打工昼捍, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留识虚,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,420評(píng)論 3 373
  • 正文 我出身青樓妒茬,卻偏偏與公主長(zhǎng)得像担锤,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子乍钻,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,107評(píng)論 2 356

推薦閱讀更多精彩內(nèi)容