Ios4 nsindepath没有行值。在iOs 4.3中可以完美运行,但在6.0中却无法实现
我的Ios4 nsindepath没有行值。在iOs 4.3中可以完美运行,但在6.0中却无法实现,ios4,ios6,nsindexpath,Ios4,Ios6,Nsindexpath,我的UITableViewController和使用nsindepaths时遇到了一个奇怪的问题。在我的UITableView中,我实现了一个自定义选项cell,它在单击的单元格下方淡入淡出。在iOs 4.3中,它可以完美地工作 我最近更新了新的xCode和iOs 6。我改变了项目中的相关点,除了每次尝试移除customCell时出现的崩溃外,其他一切都正常 它崩溃于: -[nsindepath行]中的断言失败 [……] ***由于未捕获异常“NSInternalInconsistencyExc
UITableViewController
和使用nsindepath
s时遇到了一个奇怪的问题。在我的UITableView
中,我实现了一个自定义选项cell,它在单击的单元格下方淡入淡出。在iOs 4.3中,它可以完美地工作
我最近更新了新的xCode和iOs 6。我改变了项目中的相关点,除了每次尝试移除customCell时出现的崩溃外,其他一切都正常
它崩溃于:
-[nsindepath行]中的断言失败
[……]
***由于未捕获异常“NSInternalInconsistencyException”而终止应用程序,原因:“的索引路径无效。”
与UITableView一起使用。传递到表视图的索引路径必须包含
正好有两个指定节和行的索引。请使用
如果可能,在UITableView.h中的nsindepath上的类别
我对这个错误做了一些研究。我发现,检查了上面提到的步骤,但没有帮助
在调试过程中,我发现每当我检查indexPathToDelete
的行时,它都会崩溃。它不是零,应该有一个(适用于旧的iOs版本)。在两个版本之间,他们是否使用nsindepath更改了一些内容?我已经检查了我能想到的一切
我在以下代码段中标记了错误:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
/* if user tapped the same row twice get rid of the OptionCell */
if([indexPath isEqual:self.tappedIndexPath]){
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
/* update the indexpath if needed...*/
indexPath = [self modelIndexPathforIndexPath:indexPath];
/* pointer to delete the control cell */
NSIndexPath *indexPathToDelete = self.controlRowIndexPath;
/* if same row is tapped twice => clear tapping trackers */
if([indexPath isEqual:self.tappedIndexPath]){
self.tappedIndexPath = nil;
self.controlRowIndexPath = nil;
}
/* otherwise update them appropriately */
else{
self.tappedIndexPath = indexPath; /* the row the user just tapped. */
/* Now set the location of where I need to add the option cell */
self.controlRowIndexPath = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:indexPath.section];
}
/* all logic is done, lets start updating the table */
[tableView beginUpdates];
/* lets delete the control cell, either the user tapped the same row twice or tapped another row */
if(indexPathToDelete){
/* CRASH APPEARS HERE!: */
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPathToDelete]
withRowAnimation:UITableViewRowAnimationRight];
}
/* lets add the new control cell in the right place */
if(self.controlRowIndexPath){
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:self.controlRowIndexPath]
withRowAnimation:UITableViewRowAnimationLeft];
// [self.tableView scrollToRowAtIndexPath:self.controlRowIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}
/* and we are done... */
[tableView endUpdates];
} else {
if (self.controlRowIndexPath) {
indexPath = [self modelIndexPathforIndexPath:indexPath];
NSIndexPath *indexPathToDelete = self.controlRowIndexPath;
self.tappedIndexPath = nil;
self.controlRowIndexPath = nil;
if(indexPathToDelete){
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPathToDelete]
withRowAnimation:UITableViewRowAnimationFade];
}
}
VerwaltungViewController* verwaltungViewController;
verwaltungViewController = [[VerwaltungViewController alloc] init];
[self.navigationController pushViewController:verwaltungViewController animated:YES];
}
}
编辑:modelindexpath forindexpath:
- (NSIndexPath *)modelIndexPathforIndexPath:(NSIndexPath *)indexPath
{
int whereIsTheControlRow = self.controlRowIndexPath.row;
if(self.controlRowIndexPath != nil && indexPath.row > whereIsTheControlRow)
return [NSIndexPath indexPathForRow:indexPath.row - 1 inSection:0];
return indexPath;
}
从调试器的显示中,似乎存在indexPathToDelete
基本为空的情况:没有索引,长度为零。因为它是从self.controlRowIndexPath
设置的,所以它是如何定义的?另外,您可能希望显示modelIndexPathforIndexPath
,因为它能够更改controlRowIndexPath
。controlRowIndexPath包含正确的路径(+行)。如果我在使用旧xCode和iOs 4.3的SnowLeopard Mac上调试相同的代码,我可以记录indexPathToDelete并接收1。在最新版本上执行此操作会崩溃,因为找不到行。。。“您想显示modelIndexPathForIndexPath”是什么意思?我的意思是,显示该方法的代码可能会(也可能不会)给出一些提示。某种原因导致生成了一种奇怪的nsindepath,我在您发布的文章中没有看到它,但该方法可能是催化剂。我在文章中添加了该函数。:)