2014-06-24 UITableView

來源:互聯網
上載者:User

標籤:des   style   tar   color   com   get   

1.針對cell上按鈕(UIButton)的不響應SEL

  這個問題一般是由xib導致的,當從xib中load cell的時候,cell會自動在xib上加一層contentView,所以xib中的按鈕等控制項都被contentView擋住了,可以將contentView的backgroundColor設定為黑色,可以發現確實xib中load的view被擋住了。可以在cell的awakeFromNib中利用cell的bringSubviewToFront:方法將xib中的view都添到最上層,或者利用sendSubViewToBack: 將contentView移到最底層,也可將xib中的view添加到cell的contentView上,那麼這個問題就解決了。

 

2.UITableViewDelegate 的一些方法簡介(主要提供cell的選擇,高亮,高度等操作)

 

(1)- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;

  這個方法一般用來展示一些cell剛出來時的動畫(或者說重新整理動畫),可以根據不同的cell做一些不同的事情。

 

(2)- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);

  同上,不過針對的是headerView。

 

(3)- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);

  同上,不過針對的是footerView。

 

 (4)- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath NS_AVAILABLE_IOS(6_0);

 

(5)- (void)tableView:(UITableView *)tableView didEndDisplayingHeaderView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);

 

- (void)tableView:(UITableView *)tableView didEndDisplayingFooterView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0);

 

 

 

// Variable height support

 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

 

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

 

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

 

 

 

// Use the estimatedHeight methods to quickly calcuate guessed values which will allow for fast load times of the table.

 

// If these methods are implemented, the above -tableView:heightForXXX calls will be deferred until views are ready to be displayed, so more expensive logic can be placed there.

 

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(7_0);

 

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)section NS_AVAILABLE_IOS(7_0);

 

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForFooterInSection:(NSInteger)section NS_AVAILABLE_IOS(7_0);

 

 

 

// Section header & footer information. Views are preferred over title should you decide to provide both

 

 

 

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;   // custom view for header. will be adjusted to default or specified header height

 

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;   // custom view for footer. will be adjusted to default or specified footer height

 

 

 

// Accessories (disclosures). 

 

 

 

- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath NS_DEPRECATED_IOS(2_0, 3_0);

 

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;

 

 

 

// Selection

 

 

 

// -tableView:shouldHighlightRowAtIndexPath: is called when a touch comes down on a row. 

 

// Returning NO to that message halts the selection process and does not cause the currently selected row to lose its selected look while the touch is down.

 

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0);

 

- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0);

 

- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0);

 

 

 

// Called before the user changes the selection. Return a new indexPath, or nil, to change the proposed selection.

 

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;

 

- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0);

 

// Called after the user changes the selection.

 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

 

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0);

 

 

 

// Editing

 

 

 

// Allows customization of the editingStyle for a particular cell located at ‘indexPath‘. If not implemented, all editable cells will have UITableViewCellEditingStyleDelete set for them when the table has editing property set to YES.

 

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

返回TableView為editing時cell的editingStyle

 

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0);

 

cell左滑出現的刪除按鈕,通過此函數,可以修改按鈕的名稱。 

 

// Controls whether the background is indented while editing.  If not implemented, the default is YES.  This is unrelated to the indentation level below.  This method only applies to grouped style table views.

 

- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath;

當cell為editing狀態的時候是否縮排,cell的縮排只是自動縮排contentView。

 

 

 

// The willBegin/didEnd methods are called whenever the ‘editing‘ property is automatically changed by the table (allowing insert/delete/move). This is done by a swipe activating a single row

 

- (void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath;

 

- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath;

 

 

 

// Moving/reordering

 

 

 

// Allows customization of the target row for a particular row as it is being moved/reordered

 

- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath;               

 

該函數可以實現cell在section之間的移動,也可以通過此函數禁止cell在section之間移動 

 

需跟dataSource中的一些方法配合使用

// Indentation

 

 

 

- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath; // return ‘depth‘ of row for hierarchies

 

 對於不同indexPath的cell的不同縮排

 

// Copy/Paste.  All three methods must be implemented by the delegate.

 

 下面三個函數控制cell的一些文字編輯操作(包括拷貝,剪下,粘貼,選擇,全選等操作)

 

- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(5_0);

 

特定cell是否顯示菜單

- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender NS_AVAILABLE_IOS(5_0);

 

action指的就是跟編輯有關的一些函數,如cut:,  copy:,  paste:, select:,  selectAll:,  delete:等函數

如果當action為cut: 時返回為NO,那麼菜單上就沒有剪下選項

- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender NS_AVAILABLE_IOS(5_0);

對於特定的action做特定的響應,即當使用者點擊了菜單上的某個item時我們該如何響應

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.