第三方导入思路

1、新建工程
2、导入Cocoapods框架
操作命令:打开终端操作步骤:A: cd 工程 B :vim podfile C:pod install
3、AppKey生成链接:http://bbs.mob.com/forum.php?mod=viewthread&tid=8212&extra=page%3D1
4、友盟SDK集成网址(只需要把SDK拖到工程):https://developer.umeng.com/sdk
5、新浪微博登录操作链接:http://wiki.mob.com/快速集成/
(特别提示:友盟SDK集成和新浪微博SDK,下载群里我分享的SDK压缩包)
备注:podfile导入文件参考
target ‘工程名’ do
pod ‘UMCCommon’
pod ‘UMCAnalytics’
pod ’

举个例子
导入


#import "DataManager.h"
#import "AppDelegate.h"
#import "Model.h"
@interface DataManager(){
    //声明一个APPdelegate对象属性,调用里面的被管理对象上下文 保存方法
    AppDelegate *myDelegate;
}
@end
@implementation DataManager
+(DataManager *)shareManager{
    static DataManager *manager;
    if (!manager) {
        manager = [[DataManager alloc] init];
    }
    return manager;
}
-(void)insert:(NSDictionary *)dic{
    //coreData 数据的插入
    myDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    //创建实体描述对象
    NSEntityDescription * description =  [NSEntityDescription entityForName:@"Student" inManagedObjectContext:myDelegate.persistentContainer.viewContext];
    //创建一个模型对象
    Student * student = [[Student alloc]initWithEntity:description insertIntoManagedObjectContext:myDelegate.persistentContainer.viewContext];
    student.name = dic[@"name"];
    student.create_time = dic[@"create_time"];
    student.describe = dic[@"describe"] ;
    student.start_time = dic[@"start_time"];
    student.type = dic[@"type"];
    //对数据管理器的更改进行永久保存
    [myDelegate saveContext];
    
}
-(NSArray *)select{
    myDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    //查询数据
    // (1) 设置需要抓取的实体类
    NSEntityDescription *selectEneity = [NSEntityDescription entityForName:@"Student" inManagedObjectContext:myDelegate.persistentContainer.viewContext];
    // (2)实例化抓取对象
    NSFetchRequest *req = [[NSFetchRequest alloc] init];
    // (3)设置抓取
    [req setEntity:selectEneity];
    // (4)获取抓取结果
    NSArray *res = [myDelegate.persistentContainer.viewContext executeFetchRequest:req error:nil];
    
    return  res;
}
-(void)update:(Student *)student{
    myDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [myDelegate saveContext];
}
-(void)deleteData:(Student *)student{
    myDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;

    [myDelegate.persistentContainer.viewContext deleteObject:student];
    [myDelegate saveContext];
}
@end

管理器.h
#import <Foundation/Foundation.h>
#import “Student+CoreDataClass.h”
#import “Model.h”
NS_ASSUME_NONNULL_BEGIN

@interface DataManager : NSObject
+(DataManager *)shareManager;
-(void)insert:(NSDictionary *)dic;
-(void)update:(Student *)student;

-(void)deleteData:(Student *)student;

-(NSArray *)select;
@end

NS_ASSUME_NONNULL_END


- (void)setvaluesModel:(Model *)model;
- (void)setvaluesModel:(Model *)model{
    if (model) {
        self.label1.text = model.name;
        self.label2.text = model.describe;
        self.label3.text = model.start_time;
    }
}
#import "ViewController.h"
#import "AFHTTPSessionManager.h"
#import "TableViewCell.h"
#import "Model.h"
#import "DataManager.h"
#import "Student+CoreDataClass.h"
#import "MJExtension.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>{
    NSArray *arr;
}

@property(nonatomic , strong)UITableView *ojtable;
@property(nonatomic , strong)NSMutableArray *array;

@end

@implementation ViewController
-(UITableView *)ojtable{
    if (!_ojtable) {
        _ojtable = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
        _ojtable.delegate = self;
        _ojtable.dataSource = self;
    }
    [_ojtable registerNib:[UINib nibWithNibName:@"TableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    return _ojtable;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.array = [[NSMutableArray alloc]init];
    arr = @[@"月考",@"常规考试"];
    
    [self.array addObjectsFromArray: [[DataManager shareManager] select]];
    if (![[DataManager shareManager] select]) {
        NSLog(@"数据库没东西");
        
    }else{
        NSLog(@"数据库有东西");
    }
    [self Load];
    
    [self.view addSubview:self.ojtable];
}
- (void)Load{
    AFHTTPSessionManager *manager =[AFHTTPSessionManager manager];
    [manager GET:@"http://127.0.0.1/first.json" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//        for (NSDictionary *dic in responseObject) {
//            Model *model = [Model new];
//            [model setValuesForKeysWithDictionary:dic];
//            [self.array addObject:model];
//            [[DataManager shareManager]insert:@{
//                                                @"name":model.name,
//                                                @"create_time":model.create_time,
//                                                @"student.describe":model.description,
//                                                @"start_time":model.start_time,
//                                                @"type":model.type
//            }];
//        }
        self.array = [Model mj_objectArrayWithKeyValuesArray:responseObject];
        for (NSDictionary *dic in responseObject) {
            [[DataManager shareManager]insert:dic];
        }

        [self.ojtable reloadData];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@",error);

    }];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return arr.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }else{
        return self.array.count;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

    if (self.array.count>0) {
        Model *model = self.array[indexPath.row];
        [cell setvaluesModel:model];
        [cell.Btn addTarget:self action:@selector(StartBtn:)forControlEvents:UIControlEventTouchUpInside];
        [cell.Btn setTitle:@"开始考试" forState:UIControlStateNormal];
        cell.Btn.tag = indexPath.row;
    }
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 150;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return arr[section];
}
- (void)StartBtn:(UIButton *)btn{

}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    Student *model = self.array[indexPath.row];

    [[DataManager shareManager]deleteData:model];
    [self.array removeObject:self.array[indexPath.row]];

    [self.ojtable reloadData];
}
@end

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值