iOS UIKit控制器用于显示带有照片的新闻源

时间:2013-06-22 10:22:38

标签: ios ios6 uikit uitableview

我是iOS的新手并开发iPhone的社交应用程序(使用iOS 6 SDK构建)。

我的应用程序的主要页面之一是按时间排序的垂直滚动新闻源,通常应显示状态更新。每个状态更新都会显示用户名,用户缩略图照片,一些内容文本以及最常见的一些照片或视频以及几个可用于扩展评论列表的按钮。

状态更新内容全部存储在RESTtful远程服务器中。

使用UITableViewcontroller实现它有一定意义,它还提供免费刷新:

  1. 如何在下面创建一个带有大图像/视频的自定义字幕样式UITableViewCell(类似于Facebook或Instagram)?是否有任何代码示例来创建此自定义单元格?

  2. 如果不应该使用UITableViewCell / UITableViewController构建它,应该使用哪些iOS UIKit控制器来呈现此新闻源?

  3. 可能有一些很好用的开源框架 - 你会推荐哪个?

  4. 提前感谢一大堆, 阿萨夫

1 个答案:

答案 0 :(得分:2)

他们有很多教程可以下载源代码,可以阅读UITableView的苹果documentation,在这里你可以看到教程Here 。 以下是默认情况下显示图像,标题和副标题的基本代码

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

        NSString *CellIdentifier =@"Cell";
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if (cell == nil)
        {
            cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
        cell.imageView.image=[UIImage imageNamed:[imageArray objectAtIndex:indexPath.row]];
        cell.textLabel.text=[titleArray objectAtIndex:indexPath.row];
        cell.detailTextLabel.text=[subtitle objectAtIndexPath.row];
    return cell;
    }

如果您想制作自定义单元格,请根据需要设置框架并使用SDWebImage库缓存图像

UserImageView =[[UIImageView alloc]initWithFrame:CGRectMake(5,0,70, 70) ];
nameLbl=[[UILabel alloc]initWithFrame:CGRectMake(95, 20, 200, 20)];
[nameLbl setText:nameStr];
[UserImageView setImageWithURL:[NSURL URLWithString:responseString] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
[cell.contentView addSubview:nameLbl];
[cell.contentView addSubview:UserImageView];