码迷,mamicode.com
首页 > 其他好文 > 详细

uitableview并排显示两个图片

时间:2015-05-27 22:56:48      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:ios

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ([imageArray count]/2 ==0) {
        return [imageArray count]/2;
    }
    return [imageArray count]/2+1;


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{
    static NSString *identifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    UIImageView *imageview1;
    UIImageView *imageview2;
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        imageview1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
        imageview1.tag = 100;
        imageview2 = [[UIImageView alloc]initWithFrame:CGRectMake(120, 0, 100, 100)];
        imageview2.tag = 101;
        [cell addSubview:imageview1];
        [cell addSubview:imageview2];
        
        
    }else
    {
        imageview1 = (UIImageView *)[cell viewWithTag:100];
        imageview2 = (UIImageView *)[cell viewWithTag:101];
        
    }
    if ([imageArray count]/2 ==0) {
         //鍋舵暟
        imageview1.image = [UIImage imageNamed:[imageArray objectAtIndex:indexPath.row*2]];
        imageview2.image = [UIImage imageNamed:[imageArray objectAtIndex:indexPath.row*2+1]];
    }else{
        //濂囨暟
        if (([imageArray count] - indexPath.row*2)==1) {
            imageview1.image = [UIImage imageNamed:[imageArray objectAtIndex:indexPath.row*2]];
        }else
        {imageview1.image = [UIImage imageNamed:[imageArray objectAtIndex:indexPath.row*2]];
            imageview2.image = [UIImage imageNamed:[imageArray objectAtIndex:indexPath.row*2+1]];}
    }
  
    return cell;

uitableview并排显示两个图片

标签:ios

原文地址:http://blog.csdn.net/wk598/article/details/46051499

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!