分段控制器
BottomView *guandian = [[BottomView alloc]init];
guandian.title=@"观点";
pubu *fabiao = [[pubu alloc]init];
fabiao.title=@"瀑布流";
SCNavTabBarController *scNav=[[SCNavTabBarController alloc]init];
scNav.subViewControllers=@[guandian,fabiao];
[scNav addParentController:self];
Controller
。h
#import <UIKit/UIKit.h>
typedef void(^myBlock)(NSString *str);
NS_ASSUME_NONNULL_BEGIN
@interface fabiaoViewController : UIViewController
@property(nonatomic , strong)NSMutableArray *SeleArr;// 数组
@property (nonatomic, assign) NSInteger cellCount;//包含cell的个数
@property (nonatomic,copy) myBlock block;
@property(nonatomic ,strong)NSString *zhi;
@end
。m
#import “MyinformationViewController.h”
#import “fabiaoViewController.h”
#import “DataManager.h”// Sqlite数据库
#import “videoTableViewCell.h”// 自定义表格
#import “FdetailViewController.h”//收藏详情页
@interface fabiaoViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic , strong)UITableView *ojtable;// 表格
@end
@implementation fabiaoViewController
// 懒加载
-
(UITableView *)ojtable{
if (!_ojtable) {
_ojtable = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
_ojtable.delegate = self;
_ojtable.dataSource = self;
}
//注册表格,使用xib用registerNib
[_ojtable registerNib:[UINib nibWithNibName:@“videoTableViewCell” bundle:nil] forCellReuseIdentifier:@“cell”];
return _ojtable;
} -
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.[self.view addSubview:self.ojtable];
self.navigationItem.title =@“我的收藏”;
} -
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.SeleArr.count;
}
// 单元格数据 -
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
videoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@“cell”];
cell.tiitleLabel.text = [self.SeleArr[indexPath.row]fileDescribe];cell.coverImg.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[self.SeleArr[indexPath.row]imageUrl]]]];
//好麻烦啊啊啊啊啊cell.lenthLabel.text = [self.SeleArr[indexPath.row]fileDuration];
//cell个数
_cellCount = [self.ojtable numberOfRowsInSection:0];
_zhi = [NSString stringWithFormat:@"%d",_cellCount];//把NSInteger类型转换成字符串,cao这么简单我想的那么麻烦系统自己改的语法真不靠谱
//调用block
self.block(self.zhi);
return cell;
}扫描二维码关注公众号,回复: 5543441 查看本文章 -
(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 210;
}
// 点击单元格跳转 传值url -
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
FdetailViewController *ScXq = [FdetailViewController new];
VideoModel *model = self.SeleArr[indexPath.row];
ScXq.StrUrl = model;[self.navigationController pushViewController:ScXq animated:YES];
}
// 查询 -
(void)viewDidAppear:(BOOL)animated{
//打开数据库
[[DataManager shareManage]open];
//把之前数据库的缓存数据给予新的数组
self.SeleArr = [[DataManager shareManage]select];[self.ojtable reloadData];
self.tabBarController.tabBar.hidden = NO;
}
// 左滑删除 -
(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
//打开数据库
[[DataManager shareManage]open];
//删除数据库
[[DataManager shareManage]deleteData:[self.SeleArr[indexPath.row]fileDescribe]];//根据model模型里的一个数据删除整个模型的数组数据//清空数据
[self.SeleArr removeObject:self.SeleArr[indexPath.row]];
[self.ojtable reloadData];
}// 详情
.h
#import <MediaPlayer/MediaPlayer.h>//视频播放
#import <UIKit/UIKit.h>
#import “VideoModel.h”
NS_ASSUME_NONNULL_BEGIN
@interface FdetailViewController : MPMoviePlayerViewController
@property(nonatomic , strong)VideoModel *StrUrl;
@end
.m
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.moviePlayer.contentURL = [NSURL URLWithString:self.StrUrl.fileUrl];
[self.moviePlayer play];
[self createBackBtn];//点击时进入收藏详情视频
}
-(void)createBackBtn
{
UIButton *btn =[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 50)];
[self.view addSubview:btn];
[btn addTarget:self action:@selector(pushBack) forControlEvents:UIControlEventTouchUpInside];
}
-(void)pushBack
{
[self.navigationController popViewControllerAnimated:YES];
}
Model
@interface VideoModel : NSObject
@property(nonatomic,copy)NSString *imageUrl;//图片
@property(nonatomic,copy)NSString *fileDescribe;
@property(nonatomic,copy)NSString *viewCount;//播放数
@property(nonatomic,copy)NSString *fileUrl;//视频
@property(nonatomic,copy)NSString *fileDuration;//时长
@end
.m
-(void)setValue:(id)value forUndefinedKey:(NSString *)key
{
}
View
@property (weak, nonatomic) IBOutlet UIImageView *coverImg;
@property (weak, nonatomic) IBOutlet UILabel *tiitleLabel;
@property (weak, nonatomic) IBOutlet UILabel *lenthLabel;
@property (weak, nonatomic) IBOutlet UILabel *playCountLabel;
-(void)loadDataFromModel:(VideoModel *)model;
.m
-(void)loadDataFromModel:(VideoModel *)model
{
//从model中传值给view
if (model) {
[self.coverImg sd_setImageWithURL:[NSURL URLWithString:model.imageUrl]];
self.tiitleLabel.text=model.fileDescribe;
self.lenthLabel.text=[NSString stringWithFormat:@"时长:%@ 秒",model.fileDuration];
self.playCountLabel.text=[NSString stringWithFormat:@"播放量%@",model.viewCount];
}
}
Other
//在需要点击收藏效果的页面
- (void)shoucang
{
//粗制作
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"已收藏" style:UIBarButtonItemStyleDone target:self action:nil];
//////
[[DataManager shareManage]open];
[[DataManager shareManage]create];
[[DataManager shareManage]insert:self.StrUrl];
[[DataManager shareManage]close];
}