如何为TableView创建NSIndexPath [英] How to create NSIndexPath for TableView

查看:86
本文介绍了如何为TableView创建NSIndexPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我定义的函数中删除表的第1行。要使用 deleteRowAtIndexPath ,必须使用 IndexPath 并定义一个节和行。我该如何创建这样的索引路径?

I need delete row 1 of a table in a function I have defined. In order to use deleteRowAtIndexPath you must use an IndexPath with a section and row defined. How can I create an indexpath like this?

以int {1}为唯一成员的数组将崩溃; NSLog消息指出该部分也需要定义。

An array with the int {1} as its only member will crash; the NSLog message states that the section needs to be defined as well.

*编辑 - >与单元格删除相关的代码:

*Edit -> Code relating to cell delete:

    NSIndexPath *myIP = [[NSIndexPath alloc] indexPathForRow:0 inSection:0];
    NSArray *myArray = [[NSArray alloc] initWithObjects:myIP, nil];
//  [self.tableView beginUpdates];
    [self.tableView deleteRowsAtIndexPaths:myArray withRowAnimation:UITableViewRowAnimationFade];
//  [self.tableView endUpdates];


推荐答案

使用 [NSIndexPath indexPathForRow: inSection:] 快速创建索引路径。

Use [NSIndexPath indexPathForRow:inSection:] to quickly create an index path.

编辑:在Swift 3中:

In Swift 3:

let indexPath = IndexPath(row: rowIndex, section: sectionIndex)

这篇关于如何为TableView创建NSIndexPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆