【代码笔记】判别text菲尔德里面是或不是有空,笔记text田野同志

一,效果图。

澳门金沙国际 1

【澳门金沙国际】淡出淡入效果,代码笔记。二,工程图。

澳门金沙国际 2

三,代码。

ViewController.m

澳门金沙国际 3

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    //TextField
    UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake(20, 100, 100, 200)];
    textField.backgroundColor=[UIColor redColor];
    [email protected]"123";
    [self.view addSubview:textField];

    NSLog(@"判断textField里面是否为空%i",[self textFieldIsNOTEmpt:textField]);


}

//判断textField里面是否有空
-(BOOL)textFieldIsNOTEmpt:(UITextField *)textField{
    if ([textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]].length!=0){
        return YES;
    }else {
        return NO;
    }
}

澳门金沙国际 4

 

 

   

一,效果图。 二,工程图。 三,代码。 ViewController.m –
(void)viewDidLoad { [super viewDidLoa…

【代码笔记】离线地图,笔记离线地图

一,效果图。

澳门金沙国际 5

二,工程图。

澳门金沙国际 6

三,代码。

ViewController.h

澳门金沙国际 7

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import "MapLocation.h"

@interface ViewController : UIViewController
<MKMapViewDelegate>
{
    MKMapView *_mapView;
    NSString *addressString;
}
@end

澳门金沙国际 8

 

ViewController.m

澳门金沙国际 9

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    //调用系统自带的高德地图

    //显示当前某地的离线地图
    _mapView = [[MKMapView alloc] init];
    _mapView.frame = CGRectMake(0, 40, 320,400);
    _mapView.delegate = self;
    _mapView.mapType = MKMapTypeStandard;
    [self.view addSubview:_mapView];


    [email protected]"光启城";
    NSLog(@"---addressString---%@",addressString);

    [self geocodeQuery];

}

- (void)geocodeQuery{

    if (addressString == nil || [addressString length] == 0) {
        return;
    }

    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *error) {

        NSLog(@"查询记录数:%ld",[placemarks count]);

        if ([placemarks count] > 0) {
            [_mapView removeAnnotations:_mapView.annotations];
        }

        for (int i = 0; i < [placemarks count]; i++) {

            CLPlacemark* placemark = placemarks[i];



            //调整地图位置和缩放比例
            MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(placemark.location.coordinate, 10000, 10000);
            [_mapView setRegion:viewRegion animated:YES];

            MapLocation *annotation = [[MapLocation alloc] init];
            annotation.streetAddress = placemark.thoroughfare;
            annotation.city = placemark.locality;
            annotation.state = placemark.administrativeArea;
            annotation.zip = placemark.postalCode;
            annotation.coordinate = placemark.location.coordinate;

            [_mapView addAnnotation:annotation];
        }
    }];

}

#pragma mark Map View Delegate Methods
- (MKAnnotationView *) mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>) annotation {

    MKPinAnnotationView *annotationView
    = (MKPinAnnotationView *)[_mapView dequeueReusableAnnotationViewWithIdentifier:@"PIN_ANNOTATION"];
    if(annotationView == nil) {
        annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation
                                                         reuseIdentifier:@"PIN_ANNOTATION"];
    }

    annotationView.pinColor = MKPinAnnotationColorPurple;
    annotationView.animatesDrop = YES;
    annotationView.canShowCallout = YES;

    return annotationView;
}

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    _mapView.centerCoordinate = userLocation.location.coordinate;
}

- (void)mapViewDidFailLoadingMap:(MKMapView *)theMapView withError:(NSError *)error {
    NSLog(@"error : %@",[error description]);
}


@end

澳门金沙国际 10

 

MapLocation.h

澳门金沙国际 11

#import <MapKit/MapKit.h>

@interface MapLocation : NSObject<MKAnnotation>

//街道信息属性
@property (nonatomic, copy) NSString *streetAddress;
//城市信息属性
@property (nonatomic, copy) NSString *city;
//州、省、市信息
@property (nonatomic, copy) NSString *state;
//邮编
@property (nonatomic, copy) NSString *zip;
//地理坐标
@property (nonatomic, readwrite) CLLocationCoordinate2D coordinate;

@end

澳门金沙国际 12

 

MapLocation.m

澳门金沙国际 13

//地图调用函数
#import "MapLocation.h"

@implementation MapLocation

- (NSString *)title {
    return @"您的位置!";
}
- (NSString *)subtitle {

    NSMutableString *ret = [NSMutableString new];
    if (_state)
        [ret appendString:_state];
    if (_city)
        [ret appendString:_city];
    if (_city && _state)
        [ret appendString:@", "];
    if (_streetAddress && (_city || _state || _zip))
        [ret appendString:@" • "];
    if (_streetAddress)
        [ret appendString:_streetAddress];
    if (_zip)
        [ret appendFormat:@", %@", _zip];

    return ret;
}


@end

澳门金沙国际 14

 

一,效果图。
二,工程图。 三,代码。 ViewController.h #import UIKit/UIKit.h#import
CoreLocation/CoreLocation.h#…

【代码笔记】淡出淡入效果,笔记淡出淡入

一,效果图。

澳门金沙国际 15

二,工程图。

澳门金沙国际 16

三,代码.

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController


@end

 

ViewController.m

澳门金沙国际 17

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    //UIView
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(10, 100, 200, 200)];
    view.backgroundColor=[UIColor redColor];
    [self.view addSubview:view];

    //淡出
    //[self fadeOut:view];

    //淡入
    //[self fadeIn:view];

}

//淡出
-(void) fadeOut:(UIView *)view
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.3];
    [view setAlpha:0.0f];
    [UIView commitAnimations];
}

//淡入
-(void) fadeIn:(UIView *)view
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.3];
    [view setAlpha:1.0f];
    [UIView commitAnimations];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

澳门金沙国际 18

 

 

   

一,效果图。 二,工程图。 三,代码. ViewController.h #import
UIKit/[email protected]澳门金沙国际,
ViewController : UIVi…

【代码笔记】iOS-FMDB德姆o,笔记ios-fmdbdemo

一,效果图。

澳门金沙国际 19

二,工程图。

澳门金沙国际 20

三,代码。

ViewController.h

澳门金沙国际 21

#import <UIKit/UIKit.h>
#import "FMDatabase.h"
#import "FMDatabaseQueue.h"

@interface ViewController : UIViewController
{
    FMDatabase *db;
    NSString *database_path;

}
@end

澳门金沙国际 22

 

ViewController.m

澳门金沙国际 23

#import "ViewController.h"


#define DBNAME    @"personinfo.sqlite"
#define ID        @"id"
#define NAME      @"name"
#define AGE       @"age"
#define ADDRESS   @"address"
#define TABLENAME @"PERSONINFO"


@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


    //初始化数据库存放目录
    [self addDocumentPath];
    //初始化界面
    [self addView];

    [super viewDidLoad];

}
#pragma -mark -functions
//初始化数据库存放目录
-(void)addDocumentPath
{
    //获得Documents目录
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documents = [paths objectAtIndex:0];
    NSLog(@"--documents--%@",documents);
    //添加/号,使之变成一个完整的路径
    database_path = [documents stringByAppendingPathComponent:DBNAME];
    NSLog(@"--database_path---%@",database_path);
    db = [FMDatabase databaseWithPath:database_path];
}
//初始化用户界面
-(void)addView
{

    //新建数据库
    UIButton *createBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    createBtn.frame=CGRectMake(60, 60, 200, 50);
    [createBtn addTarget:self action:@selector(doClickCreateButton) forControlEvents:UIControlEventTouchUpInside];
    [createBtn setTitle:@"createTable" forState:UIControlStateNormal];
    [self.view addSubview:createBtn];


    //插入数据库
    UIButton *insterBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    insterBtn.frame=CGRectMake(60, 130, 200, 50);
    [insterBtn addTarget:self action:@selector(doClickInsertButton) forControlEvents:UIControlEventTouchUpInside];
    [insterBtn setTitle:@"insert" forState:UIControlStateNormal];
    [self.view addSubview:insterBtn];

    //更新数据库
    UIButton *updateBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    updateBtn.frame=CGRectMake(60, 200, 200, 50);
    [updateBtn addTarget:self action:@selector(doClickUpdateButton) forControlEvents:UIControlEventTouchUpInside];
    [updateBtn setTitle:@"update" forState:UIControlStateNormal];
    [self.view addSubview:updateBtn];

    //删除数据库
    UIButton *deleteBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    deleteBtn.frame=CGRectMake(60, 270, 200, 50);
    [deleteBtn addTarget:self action:@selector(doClickDeleteButton) forControlEvents:UIControlEventTouchUpInside];
    [deleteBtn setTitle:@"delete" forState:UIControlStateNormal];
    [self.view addSubview:deleteBtn];

    //查看数据库
    UIButton *selectBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    selectBtn.frame=CGRectMake(60, 340, 200, 50);
    [selectBtn addTarget:self action:@selector(doClickSelectButton) forControlEvents:UIControlEventTouchUpInside];
    [selectBtn setTitle:@"select" forState:UIControlStateNormal];
    [self.view addSubview:selectBtn];

    //多线程
    UIButton *multithreadBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    multithreadBtn.frame=CGRectMake(60, 410, 200, 50);
    [multithreadBtn addTarget:self action:@selector(doClickMultithreadButton) forControlEvents:UIControlEventTouchUpInside];
    [multithreadBtn setTitle:@"multithread" forState:UIControlStateNormal];
    [self.view addSubview:multithreadBtn];


}
#pragma -mark -doClickAction
//新建数据库
- (void)doClickCreateButton{
    //sql 语句
    if ([db open]) {

        NSString *sqlCreateTable =  [NSString stringWithFormat:@"CREATE TABLE IF NOT EXISTS '%@' ('%@' INTEGER PRIMARY KEY AUTOINCREMENT, '%@' TEXT, '%@' INTEGER, '%@' TEXT)",TABLENAME,ID,NAME,AGE,ADDRESS];
        BOOL res = [db executeUpdate:sqlCreateTable];
        if (!res) {
            NSLog(@"error when creating db table");
        } else {
            NSLog(@"success to creating db table");
        }
        [db close];

    }
}

//插入数据库
-(void)doClickInsertButton{
    if ([db open]) {
        NSString *insertSql1= [NSString stringWithFormat:
                               @"INSERT INTO '%@' ('%@', '%@', '%@') VALUES ('%@', '%@', '%@')",
                               TABLENAME, NAME, AGE, ADDRESS, @"张三", @"13", @"济南"];
        BOOL res = [db executeUpdate:insertSql1];
        if (!res) {
            NSLog(@"error when insert db table");
        } else {
            NSLog(@"success to insert db table");
        }


        NSString *insertSql2 = [NSString stringWithFormat:
                                @"INSERT INTO '%@' ('%@', '%@', '%@') VALUES ('%@', '%@', '%@')",
                                TABLENAME, NAME, AGE, ADDRESS, @"李四", @"12", @"济南"];
        BOOL res2 = [db executeUpdate:insertSql2];

        if (!res2) {
             NSLog(@"error when insert db table");
        }else{
             NSLog(@"success to insert db table");
        }
        [db close];

    }

}
//修改数据库
-(void)doClickUpdateButton{
    if ([db open]) {
        NSString *updateSql = [NSString stringWithFormat:
                               @"UPDATE '%@' SET '%@' = '%@' WHERE '%@' = '%@'",
                               TABLENAME,   AGE,  @"15" ,AGE,  @"13"];
        BOOL res = [db executeUpdate:updateSql];
        if (!res) {
            NSLog(@"error when update db table");
        } else {
            NSLog(@"success to update db table");
        }
        [db close];

    }

}
//删除数据库
-(void)doClickDeleteButton{
    if ([db open]) {

        NSString *deleteSql = [NSString stringWithFormat:
                               @"delete from %@ where %@ = '%@'",
                               TABLENAME, NAME, @"张三"];
        BOOL res = [db executeUpdate:deleteSql];
        if (!res) {
            NSLog(@"error when delete db table");
        } else {
            NSLog(@"success to delete db table");
        }
        [db close];

    }

}
//查看数据库
-(void)doClickSelectButton{

    if ([db open]) {
        NSString * sql = [NSString stringWithFormat:
                          @"SELECT * FROM %@",TABLENAME];
        FMResultSet * rs = [db executeQuery:sql];
        while ([rs next]) {
            int Id = [rs intForColumn:ID];
            NSString * name = [rs stringForColumn:NAME];
            NSString * age = [rs stringForColumn:AGE];
            NSString * address = [rs stringForColumn:ADDRESS];
            NSLog(@"id = %d, name = %@, age = %@  address = %@", Id, name, age, address);
        }
        [db close];
    }
}
//多线程操作数据库
-(void)doClickMultithreadButton{


    FMDatabaseQueue * queue = [FMDatabaseQueue databaseQueueWithPath:database_path];
    dispatch_queue_t q1 = dispatch_queue_create("queue1", NULL);
    dispatch_queue_t q2 = dispatch_queue_create("queue2", NULL);

    dispatch_async(q1, ^{
        for (int i = 0; i < 50; ++i) {
            [queue inDatabase:^(FMDatabase *db2) {
                NSString *insertSql1= [NSString stringWithFormat:
                                       @"INSERT INTO '%@' ('%@', '%@', '%@') VALUES (?, ?, ?)",
                                       TABLENAME, NAME, AGE, ADDRESS];
                NSString * name = [NSString stringWithFormat:@"jack %d", i];
                NSString * age = [NSString stringWithFormat:@"%d", 10+i];


                BOOL res = [db2 executeUpdate:insertSql1, name, age,@"济南"];
                if (!res) {
                    NSLog(@"error to inster data: %@", name);
                } else {
                    NSLog(@"succ to inster data: %@", name);
                }
            }];
        }
    });

    dispatch_async(q2, ^{
        for (int i = 0; i < 50; ++i) {
            [queue inDatabase:^(FMDatabase *db2) {
                NSString *insertSql2= [NSString stringWithFormat:
                                       @"INSERT INTO '%@' ('%@', '%@', '%@') VALUES (?, ?, ?)",
                                       TABLENAME, NAME, AGE, ADDRESS];

                NSString * name = [NSString stringWithFormat:@"lilei %d", i];
                NSString * age = [NSString stringWithFormat:@"%d", 10+i];

                BOOL res = [db2 executeUpdate:insertSql2, name, age,@"北京"];
                if (!res) {
                    NSLog(@"error to inster data: %@", name);
                } else {
                    NSLog(@"succ to inster data: %@", name);
                }
            }];
        }
    });

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

澳门金沙国际 24

一,效果图。 二,工程图。 三,代码。 ViewController.h #import
UIKit/UIKit.h #import ” FMDatabase.h ” #import “…

相关文章