为什么 NSIndexPath 在 iOS5 中不能正常工作?

发布于 2024-12-26 01:22:12 字数 747 浏览 5 评论 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;
...
}

Where ever I used indexpath values, the app quits in iOS5. Can anyone say the exact reason for it? I red lot of questions & answers related to this. But still in a confusion.

What is the reason behind this?

What are all the changes that we should do to prevent crashing?

Where can I know these type of code-changes for the upcoming iOS versions?

Update:

Here is the crashed code:

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;
...
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷了相思 2025-01-02 01:22:12

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

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

In the someAction method, you are assigning NSIndexPath object to indexPathOfCell member. But since it is autoreleased, it will not be available in another method. So you are getting the crash. Instead, do as the following, where I suggest you to retain the variable.

- (IBAction) someAction: (UIButton *) buttonName {
  ...
  indexPathOfCell = [[MyTableView indexPathForCell:swipeCell] retain]; //swipeCell is a UITableViewCell
  ...
}
a√萤火虫的光℡ 2025-01-02 01:22:12

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

Example:-  self.myIndexPath

另一种解决方法:-

FirstIndexPath = (NSIndexPath*) [SecondIndexPath  copy];

平等以同样的方式发挥作用。喜欢:

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

}

IN IOS 5 NSIndexPath assignment (=) and equality(==) is not working . I have use self before any NSIndexPath object (My Problem has been Solved)

Example:-  self.myIndexPath

Another way Solving:-

FirstIndexPath = (NSIndexPath*) [SecondIndexPath  copy];

Equality works in same way. Like:

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

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文