0

无论我在哪里使用indexpath值,应用程序都会在 iOS5 中退出。谁能说出它的确切原因?我有很多与此相关的问题和答案。但仍处于迷茫之中。

这背后的原因是什么?

我们应该做哪些改变来防止崩溃?

我在哪里可以知道即将推出的 iOS 版本的这些类型的代码更改?

更新:

这是崩溃的代码:

MyClass.h

@interface MyClass:UIViewController <......> {
...
NSIndexPath* indexPathOfCell;
...
}

...
...


MyClass.m

....

- (IBAction) someAction: (UIButton *) buttonName {
...
indexPathOfCell = [MyTableView indexPathForCell:swipeCell]; //swipeCell is a UITableViewCell
...
}

...

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
...
[self deleteEntity: indexPathOfCell];
...
}

...
...

- (void)dealloc
{
[indexPathOfCell release];
indexPathOfCell = nil;
...
}
4

2 回答 2

3

在 someAction 方法中,您将NSIndexPath对象分配给indexPathOfCell成员。但由于它是自动发布的,它不会在其他方法中可用。所以你正在崩溃。相反,请执行以下操作,我建议您保留该变量。

- (IBAction) someAction: (UIButton *) buttonName {
  ...
  indexPathOfCell = [[MyTableView indexPathForCell:swipeCell] retain]; //swipeCell is a UITableViewCell
  ...
}
于 2012-01-10T08:55:06.067 回答
1

在 IOS 5 NSIndexPath 分配 (=) 和相等 (==) 不起作用。我在任何 NSIndexPath 对象之前使用了 self (我的问题已解决)

Example:-  self.myIndexPath

另一种解决方法:-

FirstIndexPath = (NSIndexPath*) [SecondIndexPath  copy];

平等以同样的方式运作。喜欢:

if([self.mSelectedSubUnitIndex isEqual:SecondIndexPath])
{

}
于 2012-01-10T07:34:41.940 回答