NSIndexPath *index_path;
NSUInteger u_array[] = {0, 0, 0};
index_path = [NSIndexPath indexPathWithIndexes : u_array length : 3];
上記のNSIndexPathは、長さ== 3で作成されます。これ以上のステートメントで同じことを行う方法はありますか?NSIndexPathオブジェクトを作成するより便利な方法はありますか?
NSIndexPath *index_path;
NSUInteger u_array[] = {0, 0, 0};
index_path = [NSIndexPath indexPathWithIndexes : u_array length : 3];
上記のNSIndexPathは、長さ== 3で作成されます。これ以上のステートメントで同じことを行う方法はありますか?NSIndexPathオブジェクトを作成するより便利な方法はありますか?
これはあなたが行うことができますおそらく最高です:
NSUInteger u_array[] = {0, 0, 0};
NSIndexPath *index_path = [NSIndexPath indexPathWithIndexes:u_array length:3];
あなたはUITableView
でそれを使用して話をしている場合は、UIKit additionindexPathForRow:inSection:
+ (NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section
があります。ここにそれを使用する方法は次のとおりです。答えを
NSIndexPath *myIndexPath = [NSIndexPath indexPathForRow:3 inSection:4];
おかげで... – Stanley
理由は私がこれを尋ねたのは、上記の2番目のステートメントでu_arrayの代わりに "{0、0、0}"を入れようとしたことです。コンパイラは型キャストを使用してもそれを受け入れませんでした。誰かがそれをやることができるかどうか疑問に思っていた。それができない理由について説明がありますか? – Stanley
はい:Cで中括弧を使用して初期化または配列に割り当てることはできますが、中カッコで囲まれたコンマ区切りのリストは配列ではありません。言い換えれば、Cに配列リテラルのようなものはありません。 – yuji