
ios 6 Programming Cookbook学习笔记
文章平均质量分 52
swibyn
这个作者很懒,什么都没留下…
展开
-
4.11 Moving Cells and Sections in Table Views
移动tableview中的行和Section简单的说移动行用 moveRowAtIndexPath:toIndexPath:移动Section用 moveSection:toSection:有一点需要注意的是,这里是移动,不是交换位置。比如说某个section中有3行,按顺序是 row1,row2,row3,他们的位置分别是indexPath1,indexPath2,indexPa原创 2013-11-28 17:29:46 · 776 阅读 · 0 评论 -
6.2 Accessing Variables in Block Objects
在block对象中访问变量这里有几点,你必须知道:1,block对象内的局部变量的使用方法与OC方法中使用局部变量一样。2,对于内联block 对象,局部变量不仅包括在block对象内定义的变量,还包括外层方法中定义的变量。3,OC类中实现的独立的block对象内不能使用self。如果你需要访问类对象,你应该把它作为参数传过去。4,只有在内联block对象被创建的当前逻辑范围内原创 2013-12-20 11:43:40 · 557 阅读 · 0 评论 -
6.3 Invoking Block Objects
调用block对象像调用C函数那样来调用block对象就可以了。6.1和6.2里面已经有一些调用的例子了,这里演示一个复杂点的例子。独立的block对象,我们这样来调用:void (^simpleBlock)(NSString *) = ^(NSString *paramString){/* Implement the block object here and use the原创 2013-12-20 14:23:47 · 614 阅读 · 0 评论 -
6.4 Dispatching Tasks to Grand Central Dispatch
如果你想创建一个代码块,使它能用GCD来执行怎么办?两种方法1,block 对象2,C 函数Block对象是能够利用GCD强大功能的最好方式。一些GCD已经扩展成可以接受C函数。但是,只有有限的GCD函数支持。可以被应用到GCD的C函数必须是dispatch_funtion_t类型的。这个在苹果的库里面有定义:typedef void (*dispatch_function原创 2013-12-20 15:03:11 · 694 阅读 · 0 评论 -
6.5 Performing UI-Related Tasks with GCD
GCD执行UI相关的任务UI相关的任务只能在主线程中执行,所以用GCD编程,你只能把UI相关任务分配给主队列来执行。利用dispatch_get_main_queue可以获得主队列的句柄。有两种方式可以把任务分配给主队列。他们都是异步的:dispatch_async 执行block对象dispatch_async_f 执行c函数dispatch_sync不应该在主队列中被调用,原创 2014-01-28 14:13:57 · 651 阅读 · 0 评论 -
5.2 Adding a Navigation Controller to a Storyboard
在Storyboard中增加导航控制器按照前一节的做法创建一个工程,运行之,你将得到白茫茫的一片。因为他就是一个ViewController。如果你想让一个导航控制器作为初始的控制器,该怎么做呢?在创建是选择导航控制器模版,嘻嘻,貌似没有导航控制器模版哦。其实很简单:1,点击故事板文件2,双击View外的空白区域,这样View会缩小,以便我们更好的看清全景。3,切换到Obj原创 2013-12-09 11:45:36 · 972 阅读 · 0 评论 -
6.6 Executing Non-UI Related Tasks Synchronously with GCD
好久没来这学习了,也不想说什么了,因为 --怎么说都是错哦---perform synchronous tasks that do not involve any UI-related code用dispatch_sync 执行不操作UI的同步任务比如后台下载文件对于任何不操作UI的任务来讲,你可以使用全局的并发队列。它允许你同步的或异步的执行任务。同步执行是指队列内的任务同步执行原创 2014-03-05 14:57:34 · 631 阅读 · 0 评论 -
6.7 Executing Non-UI Related Tasks Asynchronously with GCD
异步执行UI无关任务这才是GCD大显神威的地方,我保证,学完这一章节后,在以后的多线程编程中,你将深深爱上GCDdispatch_async提交block对象到队列以便异步执行dispatch_async_f提交C函数到队列,异步执行我们来实现一个功能,从网上下载一张图片并显示出来。代码框架是这样的dispatch_q原创 2014-03-06 13:53:08 · 610 阅读 · 0 评论 -
6.8 Performing Tasks After a Delay with GCD
延迟执行代码在Core Foundation中,我们可以performSelector:withObject:afterDelay:来延迟调用方法,GCD中如何实现呢?使用dispatch_after,dispatch_after_f来看个例子double delayInSeconds = 2.0;dispatch_time_t delayInNanoS原创 2014-03-06 14:37:45 · 930 阅读 · 0 评论 -
6.12 Running Tasks Synchronously with Operations
如果你想执行一系列的同步任务,你可以这么做- (void) simpleOperationEntry:(id)paramObject{ NSLog(@"Parameter Object = %@", paramObject); NSLog(@"Main Thread = %@", [NSThreadmainThread]); NSLog原创 2014-03-11 11:34:24 · 689 阅读 · 0 评论 -
6.1 Constructing Block Objects
创建block对象block 对象可以是内嵌的,也可以是独立的代码块的形式。我们先来看下传统的OC函数是怎么写的,假设一个OC函数要接收两个NSInteger并返回他们的差值,我们这样写:- (NSInteger) subtract:(NSInteger)paramValue from:(NSInteger)paramFrom{ return paramFrom - param原创 2013-12-20 09:24:12 · 710 阅读 · 0 评论 -
6.0 Introduction (Concurrency)
Concurrency啥意思啊,并发。本篇,有些是翻译的,有些不会翻译,就用自己的话把大概意思描述出来。现代的操作系统哪个不支持并发呢,是不是?单核时代,那是假并发,多核时代,真并发来了。Grand Central Dispatch, 简称 GCD:底层C API,通过block对象来工作,是用来给不同核分配任务的,程序员根本不用担心到底哪个核执行了该任务。GCD的核心是派遣队原创 2013-12-19 14:01:23 · 638 阅读 · 0 评论 -
5.4 Adding a Storyboard to an Existing Project
故事板当然有很多优点了,想不想把以前xib文件的那些工程也改造成故事板形式呢?当然了,我是不想告诉你把那么多xib文件集合成一个故事板文件会造成代码同步时容易冲突这样的缺点的,因为我也只是道听途说而已。不过我想,一个个xib文件对应在故事板里也是一大块一大块xml元素而已,即使冲突,应该也不太难解决。额.... 废话说太多了。怎么改造成故事板呢?1,File menu->New-原创 2013-12-12 09:58:49 · 747 阅读 · 0 评论 -
4.9 Constructing Headers and Footers in Table Views
创建TableView的Header 和 Footer, 显示头部和尾部。首先先来个简单的,送给急以求成的朋友。如果你先在头部和尾部简单的显示一段文本,那个实现两个代理方法即可。- (NSString *) tableView:(UITableView *)tableViewtitleForHeaderInSection:(NSInteger)section{return @"原创 2013-11-28 12:15:45 · 682 阅读 · 0 评论 -
2.30 Constructing and Displaying Styled Texts
想象一下,一个UILabel上的一段文本有两个字比较重要,老板说这两个字要加粗,还有另外两个字要提示下,要加下划线。该怎么做呢?很简单吗,分成几个Label来显示不就行了。你说对了,但一旦文本内容稍微有点变化,你可能就要调整各个label的位置了。有没有更好的办法呢?IOS提供了NSAttributedString来解决这类事情,它只需要一个label就可以把这些全搞定。天啊,他是怎么做到的。原创 2013-11-14 16:13:01 · 1069 阅读 · 0 评论 -
4.10 Displaying Context Menus on Table View Cells
显示上下文菜单在TableViewCell.....不懂怎么翻译反正就是弹出复制,粘贴,选择等等的那个。一般在手机上要复制粘贴时,我们都是先长按复制粘贴的对象。这个过程我们要实现三个代理方法tableView:shouldShowMenuForRowAtIndexPath:返回bool值来告诉ios这个cell是否弹出context menutableView:canPerfo原创 2013-11-28 15:27:35 · 873 阅读 · 0 评论 -
4.12 Deleting Cells and Sections from Table Views
删除Cells或Sections删除Sectionde 步骤1:删除data source中对应的数据2:调用UITableView 实例方法deleteSections:withRowAnimation:第一个参数是NSIndexSet 类型,可以用类方法创建indexSetWithIndex:,不过这个只能删除一个Section,想一次删除更多,用这个indexSetWithI原创 2013-11-29 13:56:30 · 821 阅读 · 0 评论 -
4.13 Utilizing the UITableViewController for Easy Creation of Table Views
利用UITableViewController来创建TableView创建过程很简单,跟UIViewController一样,只是在创建的过程中把subclass of 项选择UITableViewController就可以了。这样创建出来的模版有哪些方便之处呢?1,self.view 是一个UITableView 类型2,delegate datasouce 已经是self了原创 2013-11-29 14:54:39 · 558 阅读 · 0 评论 -
4.14 Displaying a Refresh Control for Table Views
列表的刷新列表一般都是怎么刷新的呢,一般都是往下狠狠拽一下是不是,然后就出来一个转转转的表示正在刷新,刷新完恢复。这是怎么实现的呢?很简单,比你想象的要简单首先声明创建下这个装转转的东西(书上源码)self.refreshControl = [[UIRefreshControl alloc] init];self.refreshControl = self.refreshCon原创 2013-11-29 16:43:03 · 746 阅读 · 0 评论 -
5.0 Introduction (Storyboards)
我想大家肯定都很习惯在navigationcontrollers里面push and pop view Controllers。 但是苹果相信有更好的处理办法,如果说各个view Controllers之间的切换就像一个一个故事,storyboard就像在描述这些故事。Storyboard用一种新的方法来定义screen之间的关联。假如说几年前你写了一个应用包含了20个ViewContro原创 2013-12-02 10:21:18 · 579 阅读 · 0 评论 -
5.1 Creating a Project with Storyboards
创建带故事板的工程创建过程中选择Single View Application,如果有发现 Use Storyboard 的选项,就在前面打钩,如果整个过程都没有这个选项,那你该升级XCode了。原创 2013-12-02 10:27:14 · 717 阅读 · 0 评论 -
5.3 Passing Data From One Screen to Another
用segue在各屏之间传递数据首先,请先按照5.2那样创建一个工程,这一节将讲述在点击按钮时如何传递数据给新View Controller.首先要记住这里segue是一个对象,不仅仅是简单的一个连线。在从旧View Controller 切换到新 View Controller 之前,the storyboard runtime 会创建一个UIStoryboardSegue的实例segue原创 2013-12-11 14:30:35 · 712 阅读 · 0 评论 -
6.13 Running Tasks Asynchronously with Operations
并发执行operation使用opérationqueue 或子类化NSOperation 并在main方法里面detach一个线程来执行。- (void) firstOperationEntry:(id)paramObject{ NSLog(@"%s",__FUNCTION__); NSLog(@"Parameter Object =原创 2014-03-12 09:34:56 · 587 阅读 · 0 评论 -
6.14 Creating Dependency Between Operations
在某个任务完成后才开始另一个任务没什么好说的,上例子- (void) firstOperationEntry:(id)paramObject{ NSLog(@"First Operation - Parameter Object = %@", paramObject); NSLog(@"First Operation - Main Thread = %@", [原创 2014-03-12 10:33:11 · 544 阅读 · 0 评论 -
6.9 Performing a Task Only Once with GCD
创建只执行一次的代码块使用dispatch_once上例子@implementation AppDelegatestatic dispatch_once_t onceToken;void (^executedOnlyOnce)(void) = ^{ static NSUInteger numberOfEntries =0;原创 2014-03-06 15:22:03 · 798 阅读 · 0 评论 -
7.6 Displaying Custom Pins on a Map View
自定义pin- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id MKAnnotation>)annotation{ MKAnnotationView *result = nil; if ([annotation isKindOfClass:[M原创 2014-04-08 11:39:17 · 739 阅读 · 0 评论 -
7.8 Converting Longitude and Latitude to a Meaningful Address
通过经纬度获取地址信息- (void)viewDidLoad{ [superviewDidLoad];CLLocation *location = [[CLLocationalloc] initWithLatitude:39.904989 longi原创 2014-04-08 14:13:15 · 931 阅读 · 0 评论 -
7.7 Converting Meaningful Addresses to Longitude and Latitude
通过地址获取经纬度- (void)viewDidLoad{ [superviewDidLoad];// Do any additional setup after loading the view, typically from a nib.// NSString *oreillyAddress = @"1005 Gravenstein原创 2014-04-08 14:00:43 · 789 阅读 · 0 评论 -
8.0 Introduction(Implementing Gesture Recognizers)
手势,是触摸事件的集合。在照片应用里面可以用两根手指放大缩小图片。一些常用的手势在SDK里面有相应的类。swipe rotation pinch pan long-press tap识别手势并处理的步骤1,创建相应的gesture recognizer2,加到相应的view里面3,为相应的事件写个处理方法方法要求:原创 2014-04-09 15:03:58 · 565 阅读 · 0 评论 -
8.1 Detecting Swipe Gestures
滑动手势#import "ViewController.h"@interface ViewController ()@property (nonatomic,retain)UISwipeGestureRecognizer *swipeGestureRecognizer;@end@implementa原创 2014-04-09 15:39:30 · 612 阅读 · 0 评论 -
8.5 Detecting Tap Gestures
#import "ViewController.h"@interface ViewController ()@property (nonatomic,strong)UITapGestureRecognizer *tapGestureRecognizer;@end@implementation ViewControlle原创 2014-04-10 13:49:14 · 529 阅读 · 0 评论 -
8.6 Detecting Pinch Gestures
捏放手势#import "ViewController.h"@interface ViewController ()@property (nonatomic,strong) UIPinchGestureRecognizer *pinchGestureRecognizer;@property (nonatomic,strong) UIL原创 2014-04-10 14:31:03 · 617 阅读 · 0 评论 -
8.4 Detecting Long Press Gestures
长按#import "ViewController.h"@interface ViewController ()@property (nonatomic,strong) UILongPressGestureRecognizer *longPressGestureRecognizer;@property (nonatomic,stron原创 2014-04-10 11:50:50 · 766 阅读 · 0 评论 -
8.3 Detecting Panning and Dragging Gestures
拖动@interface ViewController ()@property (nonatomic,strong) UIPanGestureRecognizer *panGestureRecognizer;@property (nonatomic,strong) UILabel *helloWorldLabel;@end原创 2014-04-10 11:02:59 · 846 阅读 · 0 评论 -
7.5 Displaying Pins with Different Colors on a Map View
自定义pin颜色MyAnnotation.h文件#import #import #define REUSABLE_PIN_RED @"Red"#define REUSABLE_PIN_GREEN @"Green" #define REUSABLE_PIN_PURPLE @"Purple"@interface M原创 2014-04-04 17:23:55 · 1455 阅读 · 0 评论 -
7.4 Displaying Pins on a Map View
MyAnnotation.h文件#import #import @interface MyAnnotation :NSObject MKAnnotation>@property (nonatomic,readonly) CLLocationCoordinate2D coordinate;@property (nonatomic,c原创 2014-04-04 16:08:40 · 545 阅读 · 0 评论 -
7.3 Pinpointing the Location of a Device
定位.h文件#import #import @interface ViewController :UIViewControllerCLLocationManagerDelegate>@end.m文件#import "ViewController.h"@interf原创 2014-04-04 15:17:02 · 546 阅读 · 0 评论 -
6.10 Grouping Tasks Together with GCD
给任务分组,并确保他们一个挨着一个执行使用 dispatch_group_create 来创建分组假设有如下三个方法,我们希望他们一个挨着一个执行- (void) reloadTableView{ /* Reload the table view here */ [NSThreadsleepForTimeInterval:3]; NSLog(原创 2014-03-07 11:19:38 · 675 阅读 · 0 评论 -
6.15 Creating Timers
定时器,循环执行某一任务看下书上的例子- (void) paint:(NSTimer *)paramTimer{ /* Do something here */ NSLog(@"Painting");}- (void) startPainting{ self.paintingTimer = [NSTimerscheduled原创 2014-03-12 17:27:12 · 653 阅读 · 0 评论 -
6.16 Creating Concurrency with Threads
创建并发线程看个例子- (void) autoreleaseThread:(id)paramSender{ @autoreleasepool { NSBundle *mainBundle = [NSBundlemainBundle]; NSString *filePath = [mainBundle pathForResourc原创 2014-03-13 14:58:59 · 501 阅读 · 0 评论