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

时间:2016-04-17 12:43:51

标签: ios objective-c iphone uitableview

在我们进入问题的主要目的之前,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 *)tableView:(UITableView *)tableView       cellForRowAtIndexPath:(NSIndexPath *)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)setSelected:(BOOL)selected animated:(BOOL)animated {
   [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}



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


    }
     return self;
 }

 @end





    @end

KASlideShow永远不会出现在UITableViewCell里面我知道有什么不对,但我无法知道修复它的位置。

1 个答案:

答案 0 :(得分:1)

为什么不将KASlideShow添加到您UITableViewController的标题视图中? 首先创建headerView并向其添加1个视图,并将其KASlideShow

的子类化

然后将您的IBOutlet幻灯片与此视图相关联

然后将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)numberOfSectionsInTableView:(UITableView *)tableView {
    return 0; // <<-- set your sections count
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 0; // <<-- set your rows count in section
}


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

    // Configure the cell...

    return cell;
}

并且您的Interface Builder应该看起来像

and your Interface Builder should look like