简体   繁体   中英

how to add KASlideShow inside a cell inside the UITableView

Before we move into the main purpose of the question, KASlideShow is a library on github . I am using this library for showing a slide show of images. After many searches on to how to implement a custom cell, I found the following: Is it possible to add UITableView within a UITableViewCell . Here is the code that i am using:

#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 never appears inside the UITableViewCell I know there is something wrong but i am not able to know where it is to fix it.

why don't u add KASlideShow to a header view in ur UITableViewController ? First create that headerView and add to it 1 more view and subclass it of KASlideShow

then connect your IBOutlet slideshow with this view

then add KASlideShow settings to ViewDidLoad

your code should look like the following code

#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;
}

and your Interface Builder should look like

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM