【移動應(yīng)用開發(fā)技術(shù)】長沙戴維營教育iOS開發(fā)面試題周刊_第1頁
【移動應(yīng)用開發(fā)技術(shù)】長沙戴維營教育iOS開發(fā)面試題周刊_第2頁
【移動應(yīng)用開發(fā)技術(shù)】長沙戴維營教育iOS開發(fā)面試題周刊_第3頁
【移動應(yīng)用開發(fā)技術(shù)】長沙戴維營教育iOS開發(fā)面試題周刊_第4頁
免費預(yù)覽已結(jié)束,剩余1頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

【移動應(yīng)用開發(fā)技術(shù)】長沙戴維營教育iOS開發(fā)面試題周刊

[TOC]assign簡單的指針賦值,不涉及引用計數(shù)的操作。copy產(chǎn)生一個新對象,引用計數(shù)為1,老對象引用計數(shù)不變。retain對象的引用計數(shù)加1。weak自動引用計數(shù)環(huán)境下使用,與assign類似,但是當(dāng)對象釋放后會自動置為nil。strong自動引用計數(shù)環(huán)境下使用,類似于retain,強引用的對象不會被釋放。center和frame是指視圖在父視圖的坐標(biāo)系統(tǒng)中的表示,center表示UIView的中心點在父視圖坐標(biāo)系統(tǒng)中的位置,frame表示UIView在父視圖坐標(biāo)系統(tǒng)中的位置和大小。bounds表示視圖在它本身的坐標(biāo)系統(tǒng)中的位置。如果修改bounds的origin會導(dǎo)致該視圖的子視圖位置發(fā)生改變,但不會影響視圖本身的位置。一般來說,frame是由center和bounds計算得來?;蛘呤钦fUIView的frame由它所擁有的CALayer的position、anchorPoint和bounds決定。

Ball

*ball

=

[[[[Ball

alloc]

init]

autorelease]

autorelease];給對象發(fā)送一次autorelease消息就會將它在自動釋放池中注冊一次。當(dāng)自動釋放池release或者drain的時候,將給注冊到里面的對象按注冊的次數(shù)發(fā)送release消息。因此最后ball對象會接收到兩次release消息,由于ball的引用計數(shù)為1,當(dāng)接收第一次release后就被釋放了。第二次release的時候會導(dǎo)致程序崩潰。KVC是由NSKeyValueCoding非正式協(xié)議所實現(xiàn)的一種機制,使得應(yīng)用程序可以通過名字或Key來訪問對象的屬性,而不是直接調(diào)用訪問器或者實例變量。示例代碼://

Copyright(c)2014年戴維營教育.Allrightsreserved.//#import

@class

DVIDog;@interface

DVIStudent

:

NSObject{@public

NSString

*_name;@protected

NSString

*_studentID;@private

float

_height;}//_age@property

(nonatomic,

assign)

int

age;@property

(nonatomic,

strong)

DVIDog

*dog;@property

(nonatomic,

strong)

NSMutableArray

*dogsArray;-

(void)printInfo;-

(void)setValueFromDict:(NSDictionary

*)dict;@end類的實現(xiàn):////

DVIStudent.m//

KVCSample////

Copyright(c)2014年戴維營教育.Allrightsreserved.//#import"DVIStudent.h"#import"DVIDog.h"@implementation

DVIStudent-

(id)init{

if

(self

=

[super

init])

{

_dogsArray

=

[NSMutableArray

array];

}

return

self;}@synthesize

age

=

_age;-

(void)printInfo{

NSLog(@"%@:%@:%d:%f",

_name,

_studentID,

_age,

_height);}-

(void)setValueFromDict:(NSDictionary

*)dict{

_name

=

[dict

objectForKey:@"name"];

_age

=

[[dict

objectForKey:@"age"]

intValue];

_height

=

[[dict

objectForKey:@"height"]

floatValue];

_studentID

=

[dict

objectForKey:@"studentID"];}-

(void)setValue:(id)value

forUndefinedKey:(NSString

*)key{

NSLog(@"%@:%@",

key,

value);}-

(void)setNilValueForKey:(NSString

*)key{

NSLog(@"%@",

key);}-

(void)setAge:(int)age{

NSLog(@"age:%d",

age);

_age

=

age;

_height

+=

0.1;}-

(int)age{

return

_age;}@end第二個類://

Copyright(c)2014年戴維營教育.Allrightsreserved.//#import

@interface

DVIDog

:

NSObject@property

(nonatomic,

assign)

int

weight;@end第二個類的實現(xiàn)://

Copyright(c)2014年戴維營教育.Allrightsreserved.//#import"DVIDog.h"@implementation

DVIDog@end使用KVC訪問屬性:_student

=

[[DVIStudent

alloc]

init];//

student.age=20;[_student

setValue:@20

forKey:@"age"];_student->_name

=

@"Zhangsan";//1._key//2.key[_student

setValue:@"1001"

forKey:@"studentID"];[_student

setValue:@1.7

forKey:@"height"];[_student

printInfo];NSLog(@"%@",

[_student

valueForKey:@"age"]);NSDictionary

*dict

=

@{@"name":@"Lisi",@"studentID":@"2002",@"age":@33,@"height":@1.8};[_student

setValueFromDict:dict];[_student

printInfo];dict

=

@{@"name":@"Wangwu",@"studentID":@"3002",@"age":@23,@"height":@0.8};[_student

setValuesForKeysWithDictionary:dict];[_student

printInfo];DVIDog

*dog

=

[[DVIDog

alloc]

init];_student.dog

=

dog;_student.dog.weight

=

20;[_student

setValue:@30

forKeyPath:@"dog.weight"];NSLog(@"%@",

[_student

valueForKeyPath:@"dog.weight"]);[_student

setValue:@12

forKey:@"weight"];[_student

setNilValueForKey:@"age"];NSLog(@"%@",

[_student

valueForKey:@"age"]);KVC中除了訪問單個屬性外,還能夠?qū)蠈傩赃M(jìn)行訪問和操作:for

(int

i

=

0;

i

<</span>

100;

++i)

{

DVIDog

*dog

=

[[DVIDog

alloc]

init];

dog.weight

=

i;

[_student.dogsArray

addObject:dog];}//NSLog(@"%@",

[_student

valueForKeyPath:@"dogsArray.@count"]);常用的集合操作:bash@avg,@max,@min,@count,@sum等

在KVC的基礎(chǔ)上,蘋果提供了KVO來獲取屬性改變的事件:添加KVO觀察者:[_student

addObserver:self

forKeyPath:@"name"

options:

NSKeyValueObservingOptionNew

|

NSKeyValueObservingOptionOld

|NSKeyValueObservingOptionPrior

context:nil];觀察者獲取通知:-

(void)observeValueForKeyPath:(NSString

*)keyPath

ofObject:(id)object

change:(NSDictionary

*)change

context:(void

*)context{

NSLog(@"%@:%@:%@",

keyPath,

object,

change);

_nameLabel.text

=

[change

objectForKey:

NSKeyValueChangeNewKey];}5.

舉例說明幾個常用的Xcode環(huán)境變量。$(BUILT_PRODUCTS_DIR)構(gòu)建成功后,目標(biāo)文件存放的位置。$(TARGET_NAME)目標(biāo)工程名。$(SRCROOT)工程文件存放的位置。$(CURRENT_PROJECT_VERSION)當(dāng)前工程版本號。不應(yīng)該對一個對象進(jìn)行強引用。代理對象可能對被代理對象擁有強引用,如UITableViewController對它里面的tableView的引用。如果tableView的代理也是強引用的話,就會導(dǎo)致因為循環(huán)引用而出現(xiàn)內(nèi)存泄漏。NSObject<-UIResponder<-UIView<-UIControl<-UIButton@synthesize編譯器自動生成setter和getter。@dynamic需要手工實現(xiàn)setter和getter,并且不能在后面用=號標(biāo)明對應(yīng)的實例變量。@compatibility_alias給類起別名。@compatibility_alias

DVINewStudent

DVIStudent;@encode獲取類型的字符串,可以用來判斷類型。@encode(int)

//i@encode(CGRect)

//{CGRect={CGPoint=ff}{CGSize=ff}}@encode(DVIStudent)

//{DVIStudent=#}給對象發(fā)送延時執(zhí)行的消息會對對象進(jìn)行retain操作,并且在方法執(zhí)

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論