0

This seems simple enough but as yet I am unable to find a solution.

Basically I have a segmented control with two options. The first is the default (and is automatically displayed on load) and when selected displays all rows in a table view. The second is a filter limiting the rows displayed. This is the exact same set-up as used on the "Recents" tab of the iPhone's Phone app that filters 'All' and 'Missed' calls.

At present I have the data loading from two different arrays. The problem is that when I swap the data there is no animation to denote that the rows have been filtered. Apple have implemented this in their Phone app but I can see no way of acheiving this.

Perhaps each cell will need to be deleted and re-added as the user switches between the two states - or perhaps setting the height of the cells that I wish to hide to 0 would acheive the same effect? Does anyone have any experience of producing this accordian-type animation?

I have looked here for some clues but am having problems rolling some code that works. Has anyone implemented this before? If so, how did you get it to work?

4

2 に答える 2

1

アニメーションを使用deleteRowsAtIndexPaths:withRowAnimation:insertRowsAtIndexPaths:withRowAnimation:てテーブルビューを呼び出すことで、同様の効果を実現できます。UITableViewRowAnimationFade

于 2010-09-03T05:11:13.343 に答える
0

reloadSections:withRowAnimation:を調べましたか?

基本的な考え方は、reloadSections:withRowAnimation: を呼び出し、UITableViewDataSource 実装でセグメント化されたコントロールの selectedSegmentIndex を切り替えることです。

データがフラット (1 つのセクションのみ) であると仮定すると、次のようになります。

- (IBAction)segmentSwitch:(id)sender
{
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (self.segmentedControl.selectedSegmentIndex)
    {
        default:
        case 0:
            return [self.allRows count];
        case 1:
            return [self.onlySomeRows count];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    id data;
    switch (self.segmentedControl.selectedSegmentIndex)
    {
        default:
        case 0:
            data = [self.allRows objectAtIndex:[indexPath row]];
            break;
        case 1:
            data = [self.onlySomeRows objectAtIndex:[indexPath row]];
            break;
    }

    //TODO: use data to populate and return a UITableViewCell...
}
于 2012-08-03T22:11:07.443 に答える