当前位置:编程学习 > wap >>

仿qq列表

在有限的手机屏幕内,想展示更多的信息给用户,同时又不使用户感觉信息很多,此时将信息分类,以QQ列表形式进行展示是一种比较不错的选择,下面对这种方法进行简单介绍。
比较方便的方法就是使用系统提供的TableView列表,当点击某一行(标题)时,判断是否已经展开,然后根据展开与否对下面的cell进行增删,利用系统提供的动画效果,列表形式已经出现,很炫的;同时为了更好的展现,可以再cell.imageView中添加小三角,指示是否展开。OK,下面代码展示:
[html]  
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  
{  
    // Navigation logic may go here. Create and push another view controller.  
    /*  
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];  
     // ...  
     // Pass the selected object to the new view controller.  
     [self.navigationController pushViewController:detailViewController animated:YES];  
     [detailViewController release];  
     */  
    if (indexPath.row!=0) {  
        return;  
    }  
      
    //动画  
    NSIndexPath *index=[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section];  
    UITableViewCell *cell=[self.tableView cellForRowAtIndexPath:index];  
    if (imageExpand ) {  
        imageExpand=!imageExpand;  
        [self rotateExpandBtnToCollapsed:cell];  
    }  
    else  
    {  
        imageExpand=!imageExpand;  
        [self rotateExpandBtnToExpanded:cell];  
    }  
      
    NSMutableArray *indexPathArray=[[NSMutableArray alloc]init];  
    for (int i=1; i<[[rootArray objectAtIndex:indexPath.section] count]; ++i) {  
        [indexPathArray addObject:[NSIndexPath indexPathForRow:indexPath.row+i inSection:indexPath.section]];  
    }  
    if(indexPath.section == 0){  
        if (Expanded) {  
            Expanded=!Expanded;  
            [tableView deleteRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationAutomatic];  
        }  
        else  
        {  
            Expanded=!Expanded;  
            [tableView insertRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationAutomatic];  
        }  
    }  
    else if(indexPath.section == 1){  
        if (Expanded_) {  
            Expanded_=!Expanded_;  
            [tableView deleteRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationAutomatic];  
        }  
        else  
        {  
            Expanded_=!Expanded_;  
            [tableView insertRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationAutomatic];  
        }  
    }  
}  
其实判断是否展开,更好的方法可以用一个数组,然后对数组内的对象取boolValue进行判断, 
补充:移动开发 , 其他 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,