在我们进入问题的主要目的之前,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
我知道有问题但我不知道在哪里修复它。
为什么不将 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;
}
你的界面生成器应该看起来像
关于ios - 如何在 UITableView 内的单元格内添加 KASlideShow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36676658/
欢迎光临 OStack程序员社区-中国程序员成长平台 (http://ostack.cn/) | Powered by Discuz! X3.4 |