2017-07-25 68 views
0

我已經使用plist創建了擴展tableview,我已經將所有值和圖像填充到了我的tableview中。在這裏,我想爲用戶單擊該單元格時爲特定單元格製作動畫。如何爲我的tableviewcell圖像單獨創建一個動畫?

例如,第一次圖像將默認,下次如果我單擊該單元格,特定單元格將被展開。在這裏我需要讓自己的形象隱藏起來;再次如果用戶按它將顯示圖像。這個怎麼做?

+0

你的意思是你想切換圖像視圖的顯示? –

+0

是的..隨着閃爍的動畫一起眨眼 –

回答

-1

http://www.iostute.com/2015/04/expandable-and-collapsable-tableview.html

您可以參閱本教程。這是一個基於可擴展tableview單元的非常好的教程。

+0

這可能是非常有幫助的,但在這裏不鼓勵鏈接的答案,因爲它們經常中斷。它們可以提供,但也許作爲本身答案的附錄。 – halfer

+1

儘管此鏈接可能回答此問題,但最好在此處包含答案的重要部分,並提供供參考的鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 - [來自評論](/ review/low-quality-posts/16826053) –

0

您可以檢查我的完整的解決方案在以下github

下面是我的一些實施。

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    movies = [[NSArray alloc] initWithObjects: 
       (NSArray*)[[Section alloc ] init:@"Istanbul" movieNames:@[@"Uskudar", @"Sariyer"] isExpanded:false], 
       (NSArray*)[[Section alloc ] init:@"Bursa" movieNames:@[@"Osmangazi", @"Mudanya", @"Nilufer"] 
       isExpanded:false], 
       (NSArray*)[[Section alloc ] init:@"Antalya" movieNames:@[@"Alanya", @"Kas"] isExpanded:false], nil 
       ];    
} 

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return movies.count; 
} 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return ((Section*)movies[section]).movies.count ; 
} 

-(void)toggleSection:(ExpandableHeaderFoorterView *)headerView withSection:(int)section 
{ 
    ((Section*)movies[section]).expanded = !((Section*)movies[section]).expanded; 
    [expandableTableView beginUpdates]; 
    for (int i= 0; i< ((Section*)movies[section]).movies.count; i++) 
    { 
     NSArray* rowsToReload = [NSArray arrayWithObjects:[NSIndexPath indexPathForRow:i inSection:section], nil]; 
     [expandableTableView reloadRowsAtIndexPaths:rowsToReload 
withRowAnimation:UITableViewRowAnimationFade]; 
    } 

    [expandableTableView endUpdates]; 

} 

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    ExpandableHeaderFoorterView* headerView = [[ExpandableHeaderFoorterView alloc] initWithCustom:((Section*)movies[section]).genre withSection:(int)section withDelegate:self]; 
    return (ExpandableHeaderFoorterView*)headerView; 
} 
1

每當用戶點擊一個細胞,UITableViewDelegate方法被調用,並在此方法可以重新裝載電池:

- (void)tableView:(UITableView *)tableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 
} 

當細胞被重新加載,下面的方法被調用(其他人之間),以及你所要做的唯一事情是與電池的當前狀態,根據返回不同的高度:

- (CGFloat)tableView:(UITableView *)tableView 
heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return (/* cell state */) ? 100.0 : 50.0; 
} 

你有多種方式來存儲您的單元的狀態,例如,您可以在模型中執行此操作。

還有其他方法,這只是一個解決方案。但關鍵是您必須重新加載單元格,並根據您要考慮的條件返回不同的高度。

相關問題