为什么 NSIndexPath 在 iOS5 中不能正常工作?
当我使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 someAction 方法中,您将
NSIndexPath
对象分配给indexPathOfCell
成员。但由于它是自动释放的,因此在其他方法中将不可用。所以你会遇到崩溃。相反,请执行以下操作,我建议您保留该变量。In the someAction method, you are assigning
NSIndexPath
object toindexPathOfCell
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.在 IOS 5 NSIndexPath 赋值 (=) 和相等 (==) 中不起作用。我在任何 NSIndexPath 对象之前使用 self (我的问题已解决)
另一种解决方法:-
IN IOS 5 NSIndexPath assignment (=) and equality(==) is not working . I have use self before any NSIndexPath object (My Problem has been Solved)
Another way Solving:-