• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - 如何在 UITableView 内的单元格内添加 KASlideShow

[复制链接]
菜鸟教程小白 发表于 2022-12-13 15:57:56 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

在我们进入问题的主要目的之前,KASlideShow 是 github 上的一个库.我正在使用这个库来显示图像的幻灯片。在对如何实现自定义单元进行多次搜索后,我发现了以下内容:Is it possible to add UITableView within a UITableViewCell .这是我正在使用的代码:

#import "HomeTableViewController.h"
#import "KASlideShow.h"
#import "CustomTableViewCell.h"
@interface HomeTableViewController ()
@property (strong,nonatomic) IBOutlet KASlideShow * slideshow;

@end

@implementation HomeTableViewController

 - (void)viewDidLoad {
[super viewDidLoad];



 }

  - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}








-(UITableViewCell *)tableViewUITableView *)tableView       cellForRowAtIndexPathNSIndexPath *)indexPath
{
    CustomTableViewCell *cell = [self.tableView   dequeueReusableCellWithIdentifier"SlideShowCell"];
   if(cell == nil)
   {
         cell = [[CustomTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier"SlideShowCell"];

       }


    [_slideshow setDelay:5]; // Delay between transitions
    [_slideshow setTransitionDuration:5]; // Transition duration
    [_slideshow setTransitionType:KASlideShowTransitionFade]; // Choose a transition type (fade or slide)
     [_slideshow setImagesContentMode:UIViewContentModeScaleAspectFill]; // Choose a content mode for images to display
     [_slideshow addImagesFromResources[@"adidas.jpg",@"adidas_neo.jpeg"]]; // Add images from resources
      [_slideshow addGesture:KASlideShowGestureTap]; // Gesture to go previous/next directly on the image
[_slideshow start]; 
       return  cell;
   }


@end







    #import <UIKit/UIKit.h>
    #import "KASlideShow.h"
    @interface CustomTableViewCell : UITableViewCell
    @property (nonatomic) IBOutlet  KASlideShow *slideshow;



  #import "CustomTableViewCell.h"
  #import "KASlideShow.h"
  @implementation CustomTableViewCell

  - (void)awakeFromNib {
    [super awakeFromNib];
// Initialization code
 }

 - (void)setSelectedBOOL)selected animatedBOOL)animated {
   [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}



- (id)initWithStyleUITableViewCellStyle)style reuseIdentifierNSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
     if (self) {
        // Initialization code


    }
     return self;
 }

 @end





    @end

KASlideShow 从来没有出现在 UITableViewCell 我知道有问题但我不知道在哪里修复它。



Best Answer-推荐答案


为什么不将 KASlideShow 添加到 UITableViewController 的标题 View 中? 首先创建 headerView 并向其添加另外 1 个 View 并将其子类化为 KASlideShow

然后将您的 IBOutlet 幻灯片与此 View 连接

然后将 KASlideShow 设置添加到 ViewDidLoad

您的代码应类似于以下代码

#import "SlideShowTableViewController.h"
#import "KASlideShow.h"

@interface SlideShowTableViewController ()
@property (strong,nonatomic) IBOutlet KASlideShow * slideShow;
@end

@implementation SlideShowTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.
    [self.slideShow setDelay:5]; // Delay between transitions
    [self.slideShow setTransitionDuration:5]; // Transition duration
    [self.slideShow setTransitionType:KASlideShowTransitionFade]; // Choose a transition type (fade or slide)
    [self.slideShow setImagesContentMode:UIViewContentModeScaleAspectFill]; // Choose a content mode for images to display
    [self.slideShow addImagesFromResources[@"adidas.jpg",@"adidas_neo.jpeg"]]; // Add images from resources
    [self.slideShow addGesture:KASlideShowGestureTap]; // Gesture to go previous/next directly on the image
    [self.slideShow start];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableViewUITableView *)tableView {
    return 0; // <<-- set your sections count
}

- (NSInteger)tableViewUITableView *)tableView numberOfRowsInSectionNSInteger)section {
    return 0; // <<-- set your rows count in section
}


- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier"reuseIdentifier" forIndexPath:indexPath];

    // Configure the cell...

    return cell;
}

你的界面生成器应该看起来像

and your Interface Builder should look like

关于ios - 如何在 UITableView 内的单元格内添加 KASlideShow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36676658/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap