self.listData = [NSArray arrayWithObjects:@"A",@"B",@"C", nil];
如何獲取listData項的索引號?獲取NSArray索引號
下面這段代碼是用來獲取的ListData項目的字符串:
c = [NSString stringWithFormat:@"%@",[listData objectAtIndex:indexPath.row];
任何想法? 由於
self.listData = [NSArray arrayWithObjects:@"A",@"B",@"C", nil];
如何獲取listData項的索引號?獲取NSArray索引號
下面這段代碼是用來獲取的ListData項目的字符串:
c = [NSString stringWithFormat:@"%@",[listData objectAtIndex:indexPath.row];
任何想法? 由於
喜歡的東西...
NSUInteger index = [listData indexOfObject:@"A"];
從the docs:
返回值 最低索引其 相應的數組值等於 anObject。如果 中的對象都不等於anObject,則 將返回NSNotFound。
討論 對象被認爲是 等於isEqual:返回YES。
**重要提示:如果anObject爲零拋出一個異常**
如果你能保證你的數組中的字符串是唯一的,然後使用indexOfObject:
會工作。否則,您需要使用其中一個indexOfObjects *方法(如indexesOfObjectsWithOptions:passingTest:
)來獲取包含您感興趣的對象的所有索引集合。