3

こんにちは、これは非常に単純なことですが、何らかの理由で私を殺しています。

indexPath.row を行の総数と比較したい:

NSInteger *rowCount = (NSInteger *) [self.tableView numberOfRowsInSection:indexPath.section];

if((NSInteger *)indexPath.row < rowCount - 1) {
    //do a
} else {
    //do b
}

しかし、何らかの理由でこれが機能していません。これを行う正しい方法はありますか?

4

3 に答える 3

4

このコードでは、ポインターやキャストは必要ありません。オブジェクトなどではなく、整数値を比較して保存しているだけです。NSInteger はオブジェクトではなく「プリミティブ」型であることを忘れないでください。

NSInteger rowCount = [self.tableView numberOfRowsInSection:indexPath.section];

if(indexPath.row < rowCount - 1) {
    //do a
} else {
    //do b
}
于 2013-09-03T08:49:15.673 に答える
0

これはうまくいきます

int rowCount = [self.tableView numberOfRowsInSection:indexPath.section];

if(indexPath.row < rowCount - 1) {
    //do a
} else {
    //do b
}
于 2013-09-03T08:47:46.230 に答える