嗨我正在與Tableview
。我有一個由Date對象組成的數組。基於日期和時間我可以如何洗牌tableview rows.This數組動態獲取值,以便如何實現這一點。如何動態刷新UITableview行
而關於我的代碼:我只是重新調整我的數組計數,並在tableview titleLabel中分配名稱。它工作正常。但我需要根據日期進行洗牌。
嗨我正在與Tableview
。我有一個由Date對象組成的數組。基於日期和時間我可以如何洗牌tableview rows.This數組動態獲取值,以便如何實現這一點。如何動態刷新UITableview行
而關於我的代碼:我只是重新調整我的數組計數,並在tableview titleLabel中分配名稱。它工作正常。但我需要根據日期進行洗牌。
可以使用-moveRowAtIndexPath的UITableView的委託方法:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
if (fromIndexPath != toIndexPath) {
//Your desired moving login here
}
}
並設置:
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
只是爲了讓這個陣列的物品洗牌。
// Shuffle part
int count = [myMutableArray count];
for (int i = 0; i < count; i++) {
int newRange = count - i;
int newI = (arc4random() % newRange) + i;
[myMutableArray exchangeObjectAtIndex:i withObjectAtIndex:newI];
}
重新載入您的tableView。
shuffle or sort by date and time? –
我的意思是我想改變基於和時間的行。 – Bittoo