1:运行程序报the file couldn't be opened because you don't have permission to view it

解决办法:项目—>targets->build settings->build options->changed the value of the "Compiler for C/C++/Objective-C" to Default Compiler. 

2:百度地图引用

.1如图引用的是.framework形式开发包时,引入的命名空间则是
#import <BaiduMapAPI/BMapKit.h>//引入所有的头文件
#import <BaiduMapAPI/BMKMapView.h>//只引入所需的单个头文件
如果是引入用的是.a形式开发包时,引入的命名空间则是
#import “BMapKit.h" .2百度地图现在提供的两个.framework的包,一个是真机一个是测试机,可以使用终端的命令把它合成一个;

3:自定义大头针百度地图

- (void)viewDidLoad {
[super viewDidLoad]; //百度地图初始化
_mapView=[[BMKMapView alloc] initWithFrame:CGRectMake(, , SCREEN_WIDTH, SCREEN_HEIGHT-NAVBARHEIGHT)];
_mapView.delegate=self;
[self.view addSubview:_mapView]; //标出坐标点
[self addPointAnnotation];
} //添加标注
- (void)addPointAnnotation
{
for (int i=; i<self.coordinates.count; i++) {
coordinateBean *model=self.coordinates[i]; BMKPointAnnotation* pointAnnotation = [[BMKPointAnnotation alloc]init];
CLLocationCoordinate2D coor;
coor.latitude = model.latitude;
coor.longitude = model.longitude;
pointAnnotation.coordinate = coor; //通过title来起到传值的作用
pointAnnotation.title=[NSString stringWithFormat:@"%d",i];
[_mapView addAnnotation:pointAnnotation];
//显示弹出窗
[_mapView selectAnnotation:pointAnnotation animated:YES]; //判断那个是中心,没有则0必传参数
if (i==self.selectIndex) {
BMKCoordinateRegion region; ////表示范围的结构体
region.center.latitude = model.latitude;// 中心中
region.center.longitude = model.longitude;
region.span.latitudeDelta = ;//经度范围(设置为0.1表示显示范围为0.2的纬度范围)
region.span.longitudeDelta = ;//纬度范围 [_mapView setRegion:region];
}
}
}
//处理自定义弹出视图
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{
if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myrenameMark"];
newAnnotationView.pinColor = BMKPinAnnotationColorPurple;
newAnnotationView.animatesDrop = YES;// 设置该标注点动画显示 newAnnotationView.image = [UIImage imageNamed:self.mapPointImageName]; //把大头针换成别的图片 int selectIndex=[((BMKPointAnnotation *)annotation).title intValue];
//获得值
coordinateBean *model=[self.coordinates objectAtIndex:[((BMKPointAnnotation *)annotation).title intValue]]; UIView *popView=[[UIView alloc]initWithFrame:CGRectMake(, , , )]; UIImage *img=[UIImage imageNamed:@"mapViewBackground"];
UIEdgeInsets edge=UIEdgeInsetsMake(, , , );
img=[img resizableImageWithCapInsets:edge resizingMode:UIImageResizingModeStretch];
UIImageView *myimage=[[UIImageView alloc] initWithImage:img];
myimage.frame=CGRectMake(, , , );
myimage.userInteractionEnabled=YES; [popView addSubview:myimage]; //自定义显示的内容
UILabel *driverName = [[UILabel alloc]initWithFrame:CGRectMake(, , , )];
driverName.backgroundColor=[UIColor clearColor];
driverName.text=model.title;
driverName.font = [UIFont systemFontOfSize:];
driverName.textColor = [UIColor blackColor];
driverName.textAlignment = NSTextAlignmentLeft;
[myimage addSubview:driverName]; UILabel *carName = [[UILabel alloc]initWithFrame:CGRectMake(, , , )];
carName.backgroundColor=[UIColor clearColor];
carName.text=model.comments;
carName.font = [UIFont systemFontOfSize:];
carName.textColor = [UIColor blackColor];
carName.textAlignment = NSTextAlignmentLeft;
[myimage addSubview:carName]; BMKActionPaopaoView *pView = [[BMKActionPaopaoView alloc]initWithCustomView:popView];
pView.frame = CGRectMake(, , , );
((BMKPinAnnotationView*)newAnnotationView).paopaoView = nil;
((BMKPinAnnotationView*)newAnnotationView).paopaoView = pView;
newAnnotationView.tag=selectIndex+; return newAnnotationView;
}
return nil;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/**
* @author wujunyang, 15-05-12 13:05:05
*
* @brief 跟对百度地图的处理
* @param animated <#animated description#>
*/
-(void)viewWillAppear:(BOOL)animated
{
[_mapView viewWillAppear]; _mapView.delegate=self;
_locationService.delegate=self;
}
/**
* @author wujunyang, 15-01-06 10:01:53
*
* 跟对百度地图的处理
*
* @param animated <#animated description#>
*/
-(void)viewWillDisappear:(BOOL)animated
{
[_mapView viewWillDisappear];
_mapView.delegate=nil;
_locationService.delegate=nil;
} 其中有个自定义model: @interface coordinateBean : NSObject
//纬度
@property(assign,nonatomic)float latitude;
//经度
@property(assign,nonatomic)float longitude;
//标题
@property(strong,nonatomic)NSString *title;
//注解
@property(strong,nonatomic)NSString *comments;
@end

 4:自动隐藏和显示工具栏和导航条

toolbar属性、toolbarItems与上一讲的navigationBar、navigationItem类似。只不过toolbarItems没有navigationItem的左右区分,它就自己一个人在做事,相当于没有下属。可以在toolbar上设置很多,比如背景颜色、背景图片、背景样式、大小位置(不过有些貌似设置无效),当然和navigationBar一样,对于它的是否显示和隐藏是由它的老爸即navigationController控制的。

所以[self.navigationController setNavigationBarHidden:YES animated:YES];也会把底部的toolBarItems给隐藏起来,如果要隐藏导航又不想底部toolBarItems被隐藏掉,可以用普通的view替代toolBarItems;

首先在viewDidLoad里设置toolBarHidden = NO, 默认是YES(隐藏的)

为了让toolbar显示,需要设置为NO(不隐藏)。

- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"隐藏导航栏";
// self.toolbarItems
self.navigationController.toolbar.barStyle = self.toolBar.barStyle;
self.navigationController.toolbarHidden = NO; [self.navigationController.toolbar setTranslucent:YES]; self.toolbarItems = [[[NSMutableArray alloc] initWithArray:self.toolBar.items] autorelease];
} 在点击中间button的时候的显示和隐藏navigation bar和toolBar 实现代码如下: - (IBAction)toggleNavigationBar:(id)sender
{
//Check the current state of the navigation bar...
BOOL navBarState = [self.navigationController isNavigationBarHidden];
//Set the navigationBarHidden to the opposite of the current state.
[self.navigationController setNavigationBarHidden:!navBarState animated:YES];
[self.navigationController setToolbarHidden:!navBarState animated:YES];
//Change the label on the button.
if (navBarState)
{
[button setTitle:@"隐藏 Navigationr and toolbar" forState:UIControlStateNormal];
[button setTitle:@"隐藏 Navigation Bar toolbar" forState:UIControlStateHighlighted];
}
else
{
[button setTitle:@"显示 Navigation Bar toolbar" forState:UIControlStateNormal];
[button setTitle:@"显示 Navigation Bar toolbar" forState:UIControlStateHighlighted];
}
}

5:View代码结构的一些建议

在viewDidload里面只做addSubview的事情,然后在viewWillAppear里面做布局的事情,最后在viewDidAppear里面做Notification的监听之类的事情。至于属性的初始化,则交给getter去做。

@interface CustomObject()
@property (nonatomic, strong) UILabel *label;
@end @implement #pragma mark - life cycle - (void)viewDidLoad
{
[super viewDidLoad]; [self.view addSubview:self.label];
} - (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated]; self.label.frame = CGRectMake(, , , );
} #pragma mark - getters and setters - (UILabel *)label
{
if (_label == nil) {
_label = [[UILabel alloc] init];
_label.text = @"";
_label.font = [UIFont systemFontOfSize:];
... ...
}
return label;
}
@end 注意:*重点,在get方法里面不能写self.noLabel;千万不要用“点”语法,这样会造成get方法死循环,因为“点”语法就是调用的get方法,所以要用下划线属性名的方法得到对象(在内存这其实是一个指针)。
@interface MasonryViewController ()
@property(nonatomic,strong)UIView *conView;
@property(nonatomic,assign)int intstate;
@end @implementation MasonryViewController - (void)viewDidLoad {
[super viewDidLoad]; [self.view addSubview:self.conView];
}
//懒加载
-(UIView *)conView
{
if(_conView==nil)
{
_conView=[[UIView alloc]init];
_conView.backgroundColor=[UIColor redColor];
}
return _conView;
} -(int)intstate
{
_intstate=;
return _intstate;
} //布局约束
-(void)viewDidLayoutSubviews
{
[self.conView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_top).with.offset();
make.left.equalTo(self.view.mas_left).with.offset();
make.right.equalTo(self.view.mas_right).with.offset();
make.height.equalTo(@);
}];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}

6: iOS中的生成随机数方法

生成0-x之间的随机正整数

int value =arc4random_uniform(x + );

生成随机正整数

int value = arc4random() 

通过arc4random() 获取0到x-1之间的整数的代码如下:

int value = arc4random() % x; 

获取1到x之间的整数的代码如下: 

int value = (arc4random() % x) + ; 

最后如果想生成一个浮点数,可以在项目中定义如下宏:

#define ARC4RANDOM_MAX      0x100000000 

然后就可以使用arc4random() 来获取0到100之间浮点数了(精度是rand()的两倍),代码如下:

double val = floorf(((double)arc4random() / ARC4RANDOM_MAX) * 100.0f);

实例(从数组中随机显示出一个背景图,再通过网络加载显示出来):

 self.bgView=[[UIImageView alloc] initWithFrame:CGRectMake(, , SCREEN_WIDTH, SCREEN_HEIGHT)];
self.bgView.image=[UIImage imageNamed:@"AppBg"];
[self.view addSubview:self.bgView];
[self.view sendSubviewToBack:self.bgView]; NSDictionary *params=[[NSDictionary alloc] init];
[[HomeMainNetAPIManager sharedManager] getBackgroundImage:params andBlock:^(id data, NSError *error) {
if (!error&&data) {
BackgroundImageBean *groundImagebean =(BackgroundImageBean *)data;
int dataNum=groundImagebean.data.count;
if (groundImagebean.data&&dataNum>) {
int r=arc4random_uniform(dataNum);
GroundImageBean *curBean=groundImagebean.data[r];
[self.bgView sd_setImageWithURL:[NSURL URLWithString:curBean.ImgUrl] placeholderImage:[UIImage imageNamed:@"AppBg"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
dispatch_async(dispatch_get_main_queue(), ^{
self.bgView.image=image;
});
}];
} }
}];

7:沙盒路径知识整理

模拟器的路径从之前的~/Library/Application Support/iPhone Simulator移动到了~/Library/Developer/CoreSimulator/Devices/

文件都在个人用户名文件夹下的一个隐藏文件夹里,中文叫资源库,他的目录其实是Library。

因为应用是在沙箱(sandbox)中的,在文件读写权限上受到限制,只能在几个目录下读写文件:
Documents:应用中用户数据可以放在这里,iTunes备份和恢复的时候会包括此目录
tmp:存放临时文件,iTunes不会备份和恢复此目录,此目录下文件可能会在应用退出后删除
Library/Caches:存放缓存文件,iTunes不会备份此目录,此目录下文件不会在应用退出删除 iTunes在与iPhone同步时,备份所有的Documents和Library文件。
iPhone在重启时,会丢弃所有的tmp文件。 查看方法:
方法1、可以设置显示隐藏文件,然后在Finder下直接打开。设置查看隐藏文件的方法如下:打开终端,输入命名
()显示Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool true
()隐藏Mac隐藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool false
()输完单击Enter键,退出终端,重新启动Finder就可以了 重启Finder:鼠标单击窗口左上角的苹果标志-->强制退出-->Finder-->
现在能看到资源库文件夹了。
打开资源库后找到/Application Support/iPhone Simulator/文件夹。这里面就是模拟器的各个程序的沙盒目录了。
方法2、这种方法更方便,在Finder上点->前往->前往文件夹,输入/Users/username/Library/Application Support/iPhone Simulator/ 前往。
username这里写用户名。 自定义类返回各目录路径: #import <Foundation/Foundation.h> @interface ICSandboxHelper : NSObject + (NSString *)homePath; // 程序主目录,可见子目录(3个):Documents、Library、tmp
+ (NSString *)appPath; // 程序目录,不能存任何东西
+ (NSString *)docPath; // 文档目录,需要ITUNES同步备份的数据存这里,可存放用户数据
+ (NSString *)libPrefPath; // 配置目录,配置文件存这里
+ (NSString *)libCachePath; // 缓存目录,系统永远不会删除这里的文件,ITUNES会删除
+ (NSString *)tmpPath; // 临时缓存目录,APP退出后,系统可能会删除这里的内容
+ (BOOL)hasLive:(NSString *)path; //判断目录是否存在,不存在则创建 实现代码: #import "ICSandboxHelper.h" @implementation ICSandboxHelper + (NSString *)homePath{
return NSHomeDirectory();
} + (NSString *)appPath
{
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSApplicationDirectory, NSUserDomainMask, YES);
return [paths objectAtIndex:];
} + (NSString *)docPath
{
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [paths objectAtIndex:];
} + (NSString *)libPrefPath
{
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
return [[paths objectAtIndex:] stringByAppendingFormat:@"/Preference"];
} + (NSString *)libCachePath
{
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
return [[paths objectAtIndex:] stringByAppendingFormat:@"/Caches"];
} + (NSString *)tmpPath
{return [NSHomeDirectory() stringByAppendingFormat:@"/tmp"];
} + (BOOL)hasLive:(NSString *)path
{
if ( NO == [[NSFileManager defaultManager] fileExistsAtPath:path] )
{
return [[NSFileManager defaultManager] createDirectoryAtPath:path
withIntermediateDirectories:YES
attributes:nil
error:NULL];
} return NO;
}

IOS开发基础知识--碎片13的更多相关文章

  1. IOS开发基础知识碎片-导航

    1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...

  2. IOS开发基础知识--碎片14

    1:ZIP文件压缩跟解压,使用ZipArchive 创建/添加一个zip包 ZipArchive* zipFile = [[ZipArchive alloc] init]; //次数得zipfilen ...

  3. IOS开发基础知识--碎片33

    1:AFNetworking状态栏网络请求效果 直接在AppDelegate里面didFinishLaunchingWithOptions进行设置 [[AFNetworkActivityIndicat ...

  4. IOS开发基础知识--碎片42

    1:报thread 1:exc_bad_access(code=1,address=0x70********) 闪退 这种错误通常是内存管理的问题,一般是访问了已经释放的对象导致的,可以开启僵尸对象( ...

  5. IOS开发基础知识--碎片50

      1:Masonry 2个或2个以上的控件等间隔排序 /** * 多个控件固定间隔的等间隔排列,变化的是控件的长度或者宽度值 * * @param axisType 轴线方向 * @param fi ...

  6. IOS开发基础知识--碎片3

    十二:判断设备 //设备名称 return [UIDevice currentDevice].name; //设备型号,只可得到是何设备,无法得到是第几代设备 return [UIDevice cur ...

  7. IOS开发基础知识--碎片11

    1:AFNetwork判断网络状态 #import “AFNetworkActivityIndicatorManager.h" - (BOOL)application:(UIApplicat ...

  8. IOS开发基础知识--碎片16

    1:Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id) 对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断对象类型 -(BOO ...

  9. IOS开发基础知识--碎片19

    1:键盘事件顺序 UIKeyboardWillShowNotification // 键盘显示之前 UIKeyboardDidShowNotification // 键盘显示完成后 UIKeyboar ...

随机推荐

  1. Rust初步(六):在C#中使用Rust组件

    上一篇文章,我们通过实例比较了一下C#和Rust的性能表现,应该说在Release模式下面,Rust进行计算密集型的运算还是有些比较明显的优势的.那么,我们有没有可能,在C#中做一些快速应用开发,而一 ...

  2. Objective-C中的集合类

    下面详细的介绍Objective-C中的集合类以及每个集合类的用法,学过其他面向对象编程语言的小伙伴们看到OC的集合类会有种莫名的亲切感,理解起来问题不大,可以类比Java中的集合类去学习. 在Obj ...

  3. Linux内存管理之bootmem分配器

    为什么要使用bootmem分配器,内存管理不是有buddy系统和slab分配器吗?由于在系统初始化的时候需要执行一些内存管理,内存分配的任务,这个时候buddy系统,slab分配器等并没有被初始化好, ...

  4. Using Headless Mode in the Java SE Platform--转

    原文地址: By Artem Ananiev and Alla Redko, June 2006     Articles Index This article explains how to use ...

  5. 关于近段时间论坛型APP 的一段舍弃

    一直以为缓存务必要做的很好,好到什么程度呢,我曾这样想,用户在下滑数刷新的时候也要做到,先加载久缓存再加载新的,同时只改变旧的某些项.这样的想法真的很好!好到我花费了三天去设计数据库和服务器的 php ...

  6. 探秘Tomcat——启动篇

    tomcat作为一款web服务器本身很复杂,代码量也很大,但是模块化很强,最核心的模块还是连接器Connector和容器Container.具体请看下图: 从图中可以看出 a. 高亮的两块是Conne ...

  7. 几个步骤轻松搞定ASP.NET 依赖注入。

    http://www.it165.net/pro/html/201407/17685.html 我在网上看到了这篇文章,这边文章主要说的方法就是通过读取配置文件来解决依赖注入的问题.但是每次新建一个依 ...

  8. Android动画的理解

    基础知识 在我们开始讲Android动画这个知识点之前,我们了解下相应的基础知识点. Shape篇 一般用Shape定义的XML文件是存放在Drawable目录下,广泛应用于在Button.TextV ...

  9. jQuery-1.9.1源码分析系列(十六)ajax——ajax框架

    ajax的介绍就不多说了,点击可看. 既然是ajax框架,那么闲谈一谈jQuery的ajax处理思路. 现在的浏览器都支持ajax,只不过不同的浏览器使用方法可能有不同(IE使用new window. ...

  10. Angularjs学习笔记9_JSON和JSONP

    说到AJAX就会不可避免的面临两个问题,第一个是AJAX以何种格式来交换数据?第二个是跨域的需求如何解决?数据可以用自定义字符串或者用XML来描述,跨域可以通过服务器端代理来解决.最被推崇或者说首选的 ...