iOSTableView的代理函数

1.必须

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    // 返回tableView的分区数

}

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

{

    // 返回每个分数数的行数

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 返回tableView中每行的内容

}


2.编辑(删除,插入等)

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 返回是否可以编辑

}

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

{

    // 对当前行数设置编辑模式(删除,插入,不可编辑,多选(|))

}

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

{

    // 真正实现编辑的方法,在这个方法里面修改数据源,刷新

}

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 修改删除按钮的文本显示

}

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

{

    // 通知委托,表视图将要被编辑时调用(删除、插入,而不是对cell内容进行编辑)

}

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

{

    // 表视图完成编辑时调用

}

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

{

    // 通知委托在编辑模式下是否需要对表视图指定行进行缩进,这个方法可以用来去掉moverow前面的空白

}


3.选择(取消选中:在下一行将要被选中后才能取消上一行的选中)

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

{

    // 通知委托指定行被选中

}

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

{

    // 通知委托指定行将被选中,返回值为NSIndexPath是指返回响应行的索引,即可以点击一行而返回另一行的索引,也可以返回nil

}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 通知委托某行被取消选中

}

- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 通知委托指定行将被取消选中

}


4.设置高度

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

{

    // 返回每一行的高度

}

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

{

    // 返回每一个sectionheader的高度

}

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

{

    // 返回每一个sectionfooter的高度

}


5.设置header和footer

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{

    // 定义每一个sectionheader的名称

}

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section

{

    // 定义每一个sectionfooter的名称

}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

{

    // 设置分区的header的视图,可以为任何UIView的子类

}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

{

    // 设置分区的footer的视图

}

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section

{

    // 通知委托将要显示sectionheader的视图

}

- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section

{

    // 通知委托将要显示sectionfooter的视图

}


6.cell的移动

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 是否可以移动

}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath

{

    // 移动调用的方法,可以在里面设置数据源的一些操作

}

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

{

    // 移动的过程中多次调用次方法,返回值是进行移动操作结束后回到的行,如果是当前行,则不论移动到哪一行都会回到当前行

    // 其中sourceIndexPath是要移动的行

    // proposedDestinationIndexPath经过的行

}

- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 通知委托指定cell已经移出可视范围

}

- (void)tableView:(UITableView *)tableView didEndDisplayingHeaderView:(UIView *)view forSection:(NSInteger)section

{

    // 通知委托指定的sectionheader已经移出可视范围

}

- (void)tableView:(UITableView *)tableView didEndDisplayingFooterView:(UIView *)view forSection:(NSInteger)section

{

    // 通知委托指定的sectionfooter已经移出可视范围

}



7.索引

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView

{

    // 返回索引的数组

}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index

{

    // 点击索引的时候调用该方法

}


8.cell即将显示

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

{

    // cell将要显示时候调用这个方法,可以在这里面修改cell的一些属性,如颜色

}


9.长按菜单

- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 是否显示长按菜单

}

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

{

    // 弹出选择菜单时会调用这个方法(复制、黏贴、全选、剪切)

}

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

{

    // 选择菜单项完成之后调用该方法

}


10.高亮显示

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 选中行是否高亮

}

- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 通知委托指定行被高亮显示

}

- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath

{

    // 通知委托表视图的指定行不再高亮显示,一般是在点击其他行的时候调用

}


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
JavaFX 的 TableView 控件提供了一些常用的函数,用于操作和管理表格数据。下面是一些常见的 TableView 控件函数: 1. getItems(): 返回 TableView 当前使用的数据源 ObservableList。 2. setItems(ObservableList<T> items): 设置 TableView 的数据源,其中泛型 T 是表格中每行数据的类型。这个方法接受一个 ObservableList 对象作为参数,用于显示在 TableView 中的数据。 3. getSelectionModel(): 获取 TableView 的 SelectionModel,用于管理 TableView 中的选中项。可以通过 SelectionModel 获取当前选中的行或单元格等信息。 4. getColumns(): 返回 TableView 中所有的列(Column)对象的 ObservableList。 5. setColumnResizePolicy(TableView.ResizePolicy policy): 设置 TableView 列的调整策略。可选的策略包括: - CONSTRAINED_RESIZE_POLICY: 列宽度会根据 TableView 的宽度自动调整。 - UNCONSTRAINED_RESIZE_POLICY: 列宽度不受限制,可以手动调整列宽。 6. setEditable(boolean editable): 设置 TableView 是否可编辑。如果设置为 true,用户可以编辑 TableView 中的单元格数据。 7. setPlaceholder(Node placeholder): 设置 TableView 在没有数据时显示的占位符节点。当 TableView 中没有数据时,可以显示一个自定义的提示信息或其他节点。 8. sort(): 对 TableView 中的数据进行排序,默认按照第一个列进行排序。如果需要自定义排序规则,可以使用 TableColumn 的 setComparator 方法。 9. refresh(): 刷新 TableView 的显示,重新加载数据。在修改了 TableView 的数据源后,可以调用 refresh() 方法来刷新表格显示。 10. scrollTo(int index): 滚动 TableView 到指定的行索引处。 11. setRowFactory(Callback<TableView<T>, TableRow<T>> rowFactory): 设置 TableView 的行工厂,用于自定义行的样式和行为。 12. setOnMouseClicked(EventHandler<? super MouseEvent> value): 设置 TableView 的鼠标点击事件处理程序。 这些函数可以帮助你在 JavaFX 中操作和管理 TableView 控件,实现更丰富的表格功能。你可以根据具体需求选择适合的函数来使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值