2012-01-10 37 views
0

我曾經使用過indexpath的值,該應用在iOS5中退出。誰能說出它的確切原因?我紅很多問題&與此相關的答案。但仍然困惑。爲什麼NSIndexPath在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; 
... 
} 
+0

你在使用最新的Xcode嗎? – 2012-01-10 07:25:56

+5

indexpath在IOS5中正常工作。問題可能是由於您使用它的方式。你能提供一小段代碼來證明錯誤嗎? – 2012-01-10 07:26:18

+0

+1 @AdamDavis,發表一些代碼崩潰的地方 – Ilanchezhian 2012-01-10 07:41:34

回答

3

在someAction方法,您要分配NSIndexPath對象indexPathOfCell成員。但由於它是自動發佈的,因此無法用其他方法提供。所以你正在崩潰。相反,請按照以下步驟進行操作,我建議您保留該變量。

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

非常感謝。我可以在.h文件中聲明retain屬性,而不是放在這裏嗎? – Confused 2012-01-10 09:55:35

+0

是的,你可以這樣做.. – Ilanchezhian 2012-01-10 10:20:54

1

在iOS 5中NSIndexPath賦值(=)和平等(==)不工作。我任何NSIndexPath對象之前已使用自(我的問題已經解決)

Example:- self.myIndexPath 

另一種方式解決: -

FirstIndexPath = (NSIndexPath*) [SecondIndexPath  copy]; 

平等工作在相同的方式。像:

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

} 
+0

這絕對沒有意義。當然,平等和賦值操作符在iOS 5.0中工作。他們沒有打破Objective-C語言的基本部分。 – 2012-01-24 18:03:18

相關問題