在iOS5和6中,我可以使用其重用標識符(在故事板中註冊)檢索表格視圖或集合視圖的單元格。我看到的大部分代碼示例在cellForItemAtIndexPath方法中定義了一個靜態NSString標識符。這對我來說似乎並不直觀 - 每次調用此方法時,重用標識符是否會重新分配?iPhone iOS什麼是實例化靜態NSString單元重用標識符的正確方法?
在我自己的代碼中,我在方法調用外拉動靜態賦值,以確保它只執行一次。
一個愚蠢的問題,但如何實例化靜態NSString只有一次?
//should I define it here, outside the method?
static NSString *kCellID = @"kCellID";
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
//or should I define it here, within the method?
static NSString *kCellID = @"kCellID";
//retrieve cell using the identifier
}