iOS   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – UITableView的委托和数据源方法大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
任何人都可以列出UITableView的委托方法和数据源方法

UITableView的代理和数据源方法是否相同?

解决方法

//_______________________________________________________________________________________________________________
// this represents the display and behavIoUr of the cells.

@protocol UITableViewDelegate<NSObject,UIScrollViewDelegate>

@optional

// Display customization

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

// Variable height support

- (CGFloat)tableView:(UITableView *)tableView heightForRowATindexPath:(NSIndexPath *)indexPath;
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

// 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 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA,__MAC_NA,__IPHONE_2_0,__IPHONE_3_0);
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;

// SELEction

// 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 __OSX_AVAILABLE_STARTinG(__MAC_NA,__IPHONE_3_0);
// Called after the user changes the SELEction.
- (void)tableView:(UITableView *)tableView didSELEctRowATindexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView didDeSELEctRowATindexPath:(NSIndexPath *)indexPath __OSX_AVAILABLE_STARTinG(__MAC_NA,__IPHONE_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;
- (NSString *)tableView:(UITableView *)tableView titleFordeleteConfirmationButtonForRowATindexPath:(NSIndexPath *)indexPath __OSX_AVAILABLE_STARTinG(__MAC_NA,__IPHONE_3_0);

// 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;

// 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 @R_450_8913@ being moved/reordered
- (NSIndexPath *)tableView:(UITableView *)tableView targeTindexPathForMoveFromRowATindexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDesTinationIndexPath;               

// Indentation

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

@end
//_______________________________________________________________________________________________________________
    // this protocol represents the data model object. as such,it supplies no information about appearance (including the cells)

@protocol UITableViewDatasource<NSObject>

@required

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

// Row display. Implementers should *always* try to reuse cells by setTing each cell's reusEIDentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets varIoUs attributes set automatically based on table (separators) and data source (accessory views,ediTing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowATindexPath:(NSIndexPath *)indexPath;

@optional

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;              // Default is 1 if not implemented

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;    // fixed font style. use custom view (UILabel) if you want something different
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;

// EdiTing

// Individual rows can opt out of having the -ediTing property set for them. If not implemented,all rows are assumed to be editable.
- (BOOL)tableView:(UITableView *)tableView canEditRowATindexPath:(NSIndexPath *)indexPath;

// Moving/reordering

// Allows the reorder accessory view to optionally be shown for a particular row. By default,the reorder control will be shown only if the datasource implements -tableView:moveRowATindexPath:toIndexPath:
- (BOOL)tableView:(UITableView *)tableView canMoveRowATindexPath:(NSIndexPath *)indexPath;

// Index

- (NSArray *)sectionIndextitlesForTableView:(UITableView *)tableView;                                                    // return list of section titles to display in section index view (e.g. "ABCD...Z#")
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndextitle:(NSString *)title aTindex:(NSInteger)index;  // tell table which section corresponds to section title/index (e.g. "B",1))

// Data manipulation - insert and delete support

// After a row has the minus or plus button invoked (based on the UITableViewCellEdiTingStyle for the cell),the datasource must commit the change
- (void)tableView:(UITableView *)tableView commitEdiTingStyle:(UITableViewCellEdiTingStylE)ediTingStyle forRowATindexPath:(NSIndexPath *)indexPath;

// Data manipulation - reorder / moving support

- (void)tableView:(UITableView *)tableView moveRowATindexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)desTinationIndexPath;

@end

大佬总结

以上是大佬教程为你收集整理的ios – UITableView的委托和数据源方法全部内容,希望文章能够帮你解决ios – UITableView的委托和数据源方法所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。