【MyLocations】标记位置App开发体会

实现功能:

1、能通过Cora Location获取地址信息

2、用户获取地址信息后能编辑相关信息

3、使用Core Data保存数据

4、使用MapKit,在Map上显示标记的位置,并可以编辑位置信息

5、能启用拍摄功能添加图片

收获一:

在iOS8里使用Cora Location获取地理位置请求不弹出窗口的解决办法

1、需要在info.plist文件里创建一个string类型的键:NSLocationWhenInUseUsageDescription

2、在初始化CLLocationManager后,调用requestWhenInUseAuthorization方法获得请求。

如图:

收获二:

// 触碰界面其他位置时关闭虚拟键盘

在viewdidload中添加:

    UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard:)];

    gestureRecognizer.cancelsTouchesInView = NO;

    [self.tableView addGestureRecognizer:gestureRecognizer];

再添加方法:

- (void)hideKeyboard:(UIGestureRecognizer *)gestureRecognizer

{

    CGPoint point = [gestureRecognizer locationInView:self.tableView];

    NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:point];

    if (indexPath !=nil && indexPath.section == 0 && indexPath.row == 0) {

        return;

    }

    [self.descriptionTextView resignFirstResponder];

}

当用户滚动文本框时关闭键盘

收获三:

使用HUD完善用户交互体验,达到一个反馈的效果

思路:

1、写一个自定义的视图类

2、点击按钮时显示该视图

收获四:

// 以下代码用于加载之前所定义的数据模型,并连接到一个SQLite数据存储中。
// 实际上任何采用Core Data的应用,以下代码的内容都是相同的。

- (NSManagedObjectModel *)managedObjectModel
{
    if (_managedObjectModel == nil) {
        NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"DataModel" ofType:@"momd"];
        NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
        
        _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
    }
    return _managedObjectModel;
}

- (NSString *)documentsDirectory
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths lastObject];
    return documentsDirectory;
}

- (NSString *)dataStorePath
{
    return [[self documentsDirectory] stringByAppendingPathComponent:@"DataStore.sqlite"];
}

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
    if (_persistentStoreCoordinator == nil) {
        NSURL *storeURL = [NSURL fileURLWithPath:[self dataStorePath]];
        _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc]
                                       initWithManagedObjectModel:self.managedObjectModel];
        NSError *error;
        
        if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
            NSLog(@"Error adding persistent store %@,%@",error,[error userInfo]);
            
            abort();
        }
    }
    return _persistentStoreCoordinator;
}

-(NSManagedObjectContext *)managedObjectContext
{
    if (_managedObjectContext == nil) {
        NSPersistentStoreCoordinator *coordinator = self.persistentStoreCoordinator;
        
        if (coordinator != nil) {
            _managedObjectContext = [[NSManagedObjectContext alloc] init];
            [_managedObjectContext setPersistentStoreCoordinator:coordinator];
        }
    }
    return _managedObjectContext;
}
View Code

收获五:

关于NSManagedObjectContext对象

该对象将用于和Core Data进行沟通。通常我 们将其描述为“scratchpad”-暂存器。我们首先对context对象进行修改,然后调用其save方法将相关的变化信息永久保存到数据存储中。这就意味着所有需要保存到Core Data中的对象都需要有一个到NSManagedObjectContext对象的引 。

收获六:

手动添加pch文件(宏定义)过程

可参考http://www.cnblogs.com/mawenqiangios/p/5195866.html

但最重要的是要注意文件的路径!

使用宏定义,简化代码。

收获七:

IOS 8.0中修改底部TabBar的颜色

在所关联的TabBarController.m中

- (void)viewDidLoad

{

    [super viewDidLoad];

    self.tabBar.tintColor=[UIColor yellowColor];

}

收获八:

当你的程序需要手写控件代码时,记得把Auto Layout取消掉!

当完成程序的功能代码后,慢慢去完善App的UI,使之更加美观,吸引用户!

原文地址:https://www.cnblogs.com/jierism/p/5779810.html