问题标签 [nsindexpath]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
5 回答
84809 浏览

ios - 获取 UITableView 的 Selected 索引

我想为UITableView. 我写了以下代码:

这始终适用于第一项。我想选择索引indexPathForRow.

请帮忙。谢谢。

0 投票
2 回答
15074 浏览

iphone - didSelectRowAtIndexPath 返回错误的 IndexPath

我遇到了一个非常令人费解的错误。我的 UITableView的第一行返回1第二行在 indexPath 中返回0 !这怎么可能呢?

在我的 `-(void)viewDidLoad` 中一切都很好。我成功地突出了第一行

我有currentRow用于跟踪选择了哪一行的变量(另一个控件根据当前选择的行进行更改)。

现在在我的 `didDeselectRowAtIndexPath` 委托函数中,我有:

日志显示以下内容:

IndexPath: <NSIndexPath 0x79509d0> 2 indexes [0, 0]当我触摸第二行时, IndexPath: <NSIndexPath 0x79509d0> 2 indexes [0, 1]当我触摸第一行时。

没有行插入或删除或排序等,甚至没有滚动。它是一个简单的 UITableView,分组样式,有 1 节和 3 行。这可能是什么原因造成的?

谢谢你的帮助,
S

0 投票
1 回答
2035 浏览

iphone - NSIndexPath:消息发送到释放的实例

您可以提供的任何帮助将不胜感激。

我有一个应用程序,它有一个 tableView、detailView、flipView 和 moreDetail View。在过渡到第 26 个元素之前移动很好。当我点击导航到翻转和 moreDetailView 的按钮时,应用程序崩溃。

我收到错误消息:[NSIndexPath row] message sent to deallocated instance

我想我可能调用 indexPath 的次数太多了,但是为什么在第 25 个元素之前一切正常,然后停止工作?NSIndexPath 是如何被释放的?我从来没有释放它。

如果你知道,请帮忙。谢谢!!!

Xcode 说问题出在这里:

0 投票
2 回答
1174 浏览

objective-c - 无法从数组中获取 indexPath.row(未声明错误 indexPath)?

我在我的 .h 中声明了一个 NSArray

该数组用于从 URL 加载 plist 数据

这是我得到的plist

我通过 tableView 显示它

如果我选择了单元格

它会弹出一个带有textField的alertView,它可以重命名plist中的数据

这是 alertView 的按钮操作

但是我在这里遇到错误“indexPath”未声明

为什么 ?plist 是一个数组,为什么我不能从数组中获取 indexPath ???

0 投票
2 回答
3289 浏览

iphone - 在 iPhone 的 Objective-C 中在 (commitEditingStyle) 之外调用 (deleteRowsAtIndexPaths)

我有一个自定义UITableViewCell,其中添加了两个自定义UIButton。在其中一个按钮上,我希望能够从内部删除单元格行myMethod()

该方法由addTarget:@selector(myMethod:)inside调用cellForRowAtIndexPath

这有效,实际方法被成功调用。

错误:

通常我会在删除单元格中的一行时这样做。这工作正常:

0 投票
1 回答
2228 浏览

iphone - 从自定义 UITableViewCell 访问 indexPath

我正在尝试创建一个 UITableView 以允许用户输入数据,类似于许多设置 UITableViews,带有一些文本字段和标注到其他表格视图的复选框。对于应用程序中的这种常见功能,这似乎不是很简单。

我无法从自定义 UITableViewCell 访问 indexPath.row。这是我分配自定义 UITableViewCell 的地方。

在我的 TextField 类的@implementation 中,在 - (id)initWithStyle: 中,我试图通过以下方式访问 indexPath:

...为了设置文本字段的标签,如:

任何人都可以阐明我的问题或指出我以编程方式创建基本设置样式的 TableViews 的方向。

谢谢

0 投票
1 回答
1078 浏览

objective-c - Deleting all table rows in a section

For my iPad project I need to be able to reload table rows. This is how it should works, depend on some "id" selected from a popupview, i need to be able to reload table rows, table rows are dynamics and has a UITextField in it. I tried to use [self.tableView reload] but for some reason it does not update the rows correctly. Something like UITextField placeholder owned by previous "id" does not change. What I have in mind is to remove all cells in that specific section and reload the table with the new "id". When i do this i got this exception:

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (3) must be equal to the number of rows contained in that section before the update (3), plus or minus the number of rows inserted or deleted from that section (0 inserted, 3 deleted).'

The project code:

Any idea what i did wrong?

0 投票
1 回答
220 浏览

memory - NSIndexPath 泄漏

我有一个非常令人费解的内存泄漏!当我点击索引部分然后在 UITableView 中手动滚动时会发生这种情况。它似乎与 NSIndexPath 相关,我只在 didSelectRowAtIndexPath:indexPath 中阅读。否则,我不会创建或存储任何 NSIndexPath 结构。

其他用户在早期的 SDK 版本中也有类似的问题,并且仅在模拟器中。我使用最新的 4.2,这个泄漏出现在模拟器和设备中。

下面是截图链接。关于导致此问题的原因的任何想法,或者有关如何在不查看汇编代码的情况下缩小范围的任何提示? http://www.maani.us/temp/Scr ​​eenshot1.png http://www.maani.us/temp/Scr​​eenshot2.png

谢谢你。

0 投票
4 回答
2204 浏览

iphone - NSIndexPath getIndexes 方法....怎么样?

我对此方法的使用以及将其列为(无效)方法的文档感到困惑。

“返回索引路径的索引”

它也在哪里返回任何东西?

不应该是:

getIndexes:提供对索引路径索引的引用。

参数 索引 指向无符号整数数组的指针。返回时,索引路径的索引。可用性 适用于 iOS 2.0 及更高版本。在 NSIndexPath.h 中声明

0 投票
1 回答
394 浏览

objective-c - cellForRowAtIndexPath(需要在indexpath中使用一个字符串和一个整数值)

亲爱的,我想在一个 tableView 中显示两个不同的数组。我将“years”数组声明为字符串,将“amount”数组声明为整数。年金额,例如:2012、2013 .... 155888、151768 当我 build7run 应用程序时,结果如下:(看起来它减少了 16 个数字)

2012:80912864
2013:79047056
2014:79046640
2015:79046640
2016:79051632
...
2020:80928544

“year”数组作为字符串工作,但作为“amount”的整数数组没有。我很确定我在cell.text= 行中使用整数格式做错了。如果你能帮助解决这个问题,我会很高兴提前谢谢

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

[NSNumber numberWithInt:[amount objectAtIndex:row]]];

}