2016-04-22 36 views
0

嗨我正在与Tableview。我有一个由Date对象组成的数组。基于日期和时间我可以如何洗牌tableview rows.This数组动态获取值,以便如何实现这一点。如何动态刷新UITableview行

而关于我的代码:我只是重新调整我的数组计数,并在tableview titleLabel中分配名称。它工作正常。但我需要根据日期进行洗牌。

+0

shuffle or sort by date and time? –

+0

我的意思是我想改变基于和时间的行。 – Bittoo

回答

0

可以使用-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; 
} 
0
  1. 你有阵 - 数据源的表。
  2. 只是为了让这个阵列的物品洗牌。

    // 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]; 
    } 
    
  3. 重新载入您的tableView。

+0

感谢您的replay.But如何洗牌阵列。 – Bittoo

+0

我用shuffle更新了部分代码 – gerram

+0

的答案但是我需要指定我的日期值请帮助我 – Bittoo