传值

作者: 电子竞技不需要视力 | 来源:发表于2018-12-21 08:18 被阅读0次

//

//  AppDelegate.h

//  test two

//

//  Created by 刘皇帝 on 2018/12/10.

//  Copyright © 2018 刘皇帝. All rights reserved.

//

#import

#import

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property(readonly,strong)NSPersistentContainer*persistentContainer;

- (void)saveContext;

@end

//

//  AppDelegate.m

//  test two

//

//  Created by 刘皇帝 on 2018/12/10.

//  Copyright © 2018 刘皇帝. All rights reserved.

//

#import "AppDelegate.h"

#import "ViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {

    self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];

    return YES;

}

- (void)applicationWillResignActive:(UIApplication*)application {

    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.

}

- (void)applicationDidEnterBackground:(UIApplication*)application {

    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}

- (void)applicationWillEnterForeground:(UIApplication*)application {

    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

}

- (void)applicationDidBecomeActive:(UIApplication*)application {

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}

- (void)applicationWillTerminate:(UIApplication*)application {

    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

    // Saves changes in the application's managed object context before the application terminates.

    [self saveContext];

}

#pragma mark - Core Data stack

@synthesizepersistentContainer =_persistentContainer;

- (NSPersistentContainer*)persistentContainer {

    // The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it.

    @synchronized (self) {

        if (_persistentContainer == nil) {

            _persistentContainer= [[NSPersistentContaineralloc]initWithName:@"test_two"];

            [_persistentContainerloadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription*storeDescription,NSError*error) {

                if(error !=nil) {

                    // Replace this implementation with code to handle the error appropriately.

                    // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.

                    /*

                     Typical reasons for an error here include:

                     * The parent directory does not exist, cannot be created, or disallows writing.

                     * The persistent store is not accessible, due to permissions or data protection when the device is locked.

                     * The device is out of space.

                     * The store could not be migrated to the current model version.

                     Check the error message to determine what the actual problem was.

                    */

                    NSLog(@"Unresolved error %@, %@", error, error.userInfo);

                    abort();

                }

            }];

        }

    }

    return _persistentContainer;

}

#pragma mark - Core Data Saving support

- (void)saveContext {

    NSManagedObjectContext *context = self.persistentContainer.viewContext;

    NSError*error =nil;

    if([contexthasChanges] && ![contextsave:&error]) {

        // Replace this implementation with code to handle the error appropriately.

        // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.

        NSLog(@"Unresolved error %@, %@", error, error.userInfo);

        abort();

    }

}

@end

//

//  ViewController.h

//  test two

//

//  Created by 刘皇帝 on 2018/12/10.

//  Copyright © 2018 刘皇帝. All rights reserved.

//

#import

@interfaceViewController :UIViewController

@end

//

//  ViewController.m

//  test two

//

//  Created by 刘皇帝 on 2018/12/10.

//  Copyright © 2018 刘皇帝. All rights reserved.

//

#import "ViewController.h"

#import "SecondViewController.h"

#import

#import

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    //导航条

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"附近违章高发地" style:UIBarButtonItemStyleDone target:self action:@selector(Cilck)];

    [AMapServices sharedServices].enableHTTPS = YES;

    ///初始化地图

    MAMapView*_mapView = [[MAMapViewalloc]initWithFrame:self.view.bounds];

    ///把地图添加至view

    MAUserLocationRepresentation *r = [[MAUserLocationRepresentation alloc] init];

    r.showsAccuracyRing = NO;///精度圈是否显示,默认YES

    r.showsHeadingIndicator = NO;///是否显示方向指示(MAUserTrackingModeFollowWithHeading模式开启)。默认为YES

    r.strokeColor = [UIColor blueColor];///精度圈 边线颜色, 默认 kAccuracyCircleDefaultColor

    r.lineWidth = 2;///精度圈 边线宽度,默认0

    //    r.locationDotBgColor = [UIColor greenColor];///定位点背景色,不设置默认白色

    r.fillColor= [UIColorredColor];

    r.strokeColor= [UIColorblackColor];

    [_mapViewupdateUserLocationRepresentation:r];

    _mapView.showsUserLocation = YES;

    _mapView.userTrackingMode = MAUserTrackingModeFollow;

    [self.viewaddSubview:_mapView];

    [AMapServices sharedServices].enableHTTPS = YES;

}

-(void)Cilck{

    //跳转到违章的页面

    SecondViewController *sec = [[SecondViewController alloc] init];

    [self.navigationController pushViewController:sec animated:YES];

}

@end

//

//  SecondViewController.h

//  test two

//

//  Created by 刘皇帝 on 2018/12/10.

//  Copyright © 2018 刘皇帝. All rights reserved.

//

#import

NS_ASSUME_NONNULL_BEGIN

@interfaceSecondViewController :UIViewController

@end

NS_ASSUME_NONNULL_END

//

//  SecondViewController.m

//  test two

//

//  Created by 刘皇帝 on 2018/12/10.

//  Copyright © 2018 刘皇帝. All rights reserved.

//

#import "SecondViewController.h"

#import "AFNetworking.h"

#import "PostViewController.h"

@interface SecondViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *table;

@property(nonatomic,strong) NSMutableArray *dataScour;

@end

@implementationSecondViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    //设置头视图

    self.title=@"查看违章";

    _table = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];

    _table.delegate=self;

    _table.dataSource = self;

    [self.view addSubview:_table];

    _dataScour = [[NSMutableArray alloc] init];

    _dataScour = @[@"平泉路中监控抓拍",@"平泉路公交入口1闭路监控抓拍"];

    NSDictionary*params =  @{@"lat":@"经度",@"lon":@"纬度",@"key":@"6d96ee265cc090b418ee51257ff9c48f",@"page":@"dwad",@"pagesize":@"",@"r":@""};

    [self postDateUrl:@"http://v.juhe.cn/wzpoints/query" body:params

     ];

}

- (void)postDateUrl:(NSString*)url body:(NSDictionary*)body

{

    [PostViewControllergetDataWithString:urlbody:bodyblock:^(idblock) {

        //block 是请求回得数据

    }];

}

-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{

    return _dataScour.count;

}

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{

    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];

    cell.textLabel.text=_dataScour[indexPath.row];

    returncell;

}

@end

//

//  PostViewController.h

// 

//

//  Created by 刘皇帝 on 2018/12/10.

//

#import

#import "AFNetworking.h"

NS_ASSUME_NONNULL_BEGIN

typedefvoid(^AFNData)(idblock);

@interfacePostViewController :UIViewController

+(void)getDataWithString:(NSString*)string body:(NSDictionary*)parameters block:(AFNData)block;

@end

NS_ASSUME_NONNULL_END

//

//  PostViewController.m

// 

//

//  Created by 刘皇帝 on 2018/12/10.

//

#import "PostViewController.h"

#import "AFNetworking.h"

@interface PostViewController ()

@end

@implementationPostViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    AFHTTPSessionManager *manger = [AFHTTPSessionManager manager];

    NSDictionary *dic = @{@"lat":@"string"};

    [mangerPOST:@"http://v.juhe.cn/wzpoints/query"parameters:dicsuccess:^(NSURLSessionDataTask*_Nonnulltask,id  _NullableresponseObject) {

        NSLog(@"%@",responseObject);

    }failure:^(NSURLSessionDataTask*_Nullabletask,NSError*_Nonnullerror) {

    }];

}

+ (void)getDataWithString:(NSString*)string body:(NSDictionary*)parameters block:(AFNData)block

{

    AFNetworkReachabilityManager *netWorkManager = [AFNetworkReachabilityManager sharedManager];

    NSString*url_string = [NSStringstringWithFormat:@"%@",string];

    url_string = [url_stringstringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];

//    NSDictionary *params =  [NSDictionary dictionaryWithObjectsAndKeys:@"参数1",@"lat",@"参数2",@"lon",@"参数3",@"key", nil];

    [managerPOST:url_stringparameters:parameterssuccess:^(NSURLSessionTask*task,idresponseObject)  {

//        [netWorkManager stopMonitoring];

        NSLog(@"%@",responseObject);

        block(responseObject);

    }failure:^(NSURLSessionTask*operation,NSError*error) {

        NSLog(@"失败 === %@",error);

        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

            NSLog(@"Error: %@", error);

        });

    }];

}

/*

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    // Get the new view controller using [segue destinationViewController].

    // Pass the selected object to the new view controller.

}

*/

@end

相关文章

  • iOS的五种传值

    前言 iOS常见的五种传值分别为属性传值,通知传值,代理传值,block传值,单例传值 属性传值 用于正向传值,简...

  • 页面传值-03

    一、传值分类 页面传值基本分为两种:正向传值和反向传值。 二、传值方式 传值,最基本的无非就是代理传值、通知传值、...

  • iOS 页面(代理、通知、block、单例、属性)传值

    一、传值分类 页面传值基本分为两种:正向传值和反向传值。 二、传值方式 传值,最基本的无非就是代理传值、通知传值、...

  • iOS-传值方式

    传值方式:1、属性传值 方法传值2、代理传值3、单例传值 4、通知传值 NSNotificationCente...

  • Swift常用的界面传值(属性传值、协议传值、闭包传值)

    1、属性传值 属性传值多用于正向传值(A->B) 2、代理传值 代理传值多用于反向传值(B->A) 3、闭包传值 ...

  • Vue组件间关系及六种传值方式

    前言: 六种传值方式为: 属性传值 $refs $parent 通知传值(广播传值) 本地传值 路由传值 在介绍组...

  • 【iOS开发细节】之- delegate代理的使用

    在iOS开发中、好多时候需要涉及到页面传值、而传值又分为正向传值和反向传值 一、 传值 1、正向传值 2、反向传值...

  • reactNative 之组件传值和反向传值

    在项目中我们经常会遇到传值,传值有正向传值和反向传值,比如1.正向传值:从A组件push到B组件传值2.反向传值:...

  • 代理

    不同页面间传值是必不可少,传值的方式有很多(方法传值,属性传值,代理传值,单例传值) ,这里主要总结下属性传值和代...

  • ios常用的三种传值方式

    iOS中有多种方案可以实现页面之间的传值,例如:属性传值、代理传值、block传值、单例传值...。常用的三种传值...

网友评论

      本文标题:传值

      本文链接:https://www.haomeiwen.com/subject/xjbpkqtx.html