ios 做瀑布流效果大致思路

      网上下载了一个ios做瀑布流图片展示源码,之前借助做web的经验,我已为ios类似于css style中有个float:left的效果,然后形成瀑布流效果,或者像用html中做个表格分成一行几列,然后在里面填充内容。


      刚下载瀑布流demo大致意路是这样:

     1. 总先做成几列是事先要清楚,有多少条记录,这个可以从json或者xml中读取后知道(json或xml最好将图片的高度和宽度也显示出来,便于后面用到)。

     2. 假设要做成3列,就用三个uitableview,宽度平均,高度动态,页面高度取uitableview中最高的。

     3. 三个uitableview初始化的时候用到tag(我越来越觉得tag在ios中的用处很大,就像js中读取html控件中的id一样),然后showsVerticalScrollIndicator和scrollEnabled设为no,separatorStyle设为UITableViewCellSeparatorStyleNone,添加到UIview中

    4.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
     return 当行记录数/列;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    int  arrIndex=  当前indexPath.row * 列(3)+当前indexPath.column;|
   return [[XML/JSON objectAtIndex:arrIndex] objectForKey:@"高度"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   //从数据源中得到当前数组对应的数据,然后再用uitableviewcell填充

 

感谢源码作者下载地址:http://code4app.com/codesample/4fdfecd96803fa117f000000

posted @ 2012-06-29 10:29  alex hu  阅读(6371)  评论(3编辑  收藏  举报