iphone试题.docx

上传人:b****8 文档编号:10278182 上传时间:2023-02-09 格式:DOCX 页数:16 大小:21.31KB
下载 相关 举报
iphone试题.docx_第1页
第1页 / 共16页
iphone试题.docx_第2页
第2页 / 共16页
iphone试题.docx_第3页
第3页 / 共16页
iphone试题.docx_第4页
第4页 / 共16页
iphone试题.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

iphone试题.docx

《iphone试题.docx》由会员分享,可在线阅读,更多相关《iphone试题.docx(16页珍藏版)》请在冰豆网上搜索。

iphone试题.docx

iphone试题

基础知识

1.objc是扩充C的面向对象,开发macosx的编程语言。

2.objc中的减号与加号

①减号表示一个函数、或者方法或者消息的开始(在一个类的实例上被调用和实施)

②加号表示其他的函数可以直接调用这个类中的方法,而不用创建这个类的实例

3.NS开发包

乔布斯的NextStep公司缩写,现今macos使用NS这套函数库

4.#import作用如同#include,用于声明头文件。

5.nil表示空指针,相当于java的null

6.objc中使用字符串,前面要加上"@",是因为在前面加上"符号",编译器在编译的时候会在程序中给你留出位置,这样才能保证这个字符串不会丢失。

(@是把C的字符串转成NSString的一个简写)

7.开发objc类,需要创建一个头文件和一个实现文件

①头文件(.h):

包含类的实例变量的名称和类型、描述方法参数和返回值类型的方法签名;

②实现文件(.m):

包含这些方法的实现代码,以及对别的类不可见的,仅与实现本身相关的局部变量的声明和使用。

8.九宫格解法原理;(右上解法)

左出右写入、右出左写入、上出下写入、下出上写入、重排置下;

9.iphone应用程序的项目基本结构

classes:

里面存放object-c类源代码文件(可以创建子文件夹来组织代码);

othersources:

存放除objective-c类之外的源代码文件;

resources:

包含应用程序中的非代码文件(因为应用程序只能在自己的沙盒中运行,不然找不到);

Frameworks:

特殊的库,可以存放库、框架、图像、声音等资源;

Products:

包含项目在编译时生成的应用程序(xxx.app);

10.Info.plist文件里的bundleidentifier(束标识符)

它是应用程序的唯一标识符,要始终配置,命名格式为:

顶级Internet域+.+公司名称+.+应用名称;

11.一个在代码里对nib中对象(UILabel、UITextField等)的引用被称为一个插座变量(outlet),用关键字IBOutlet标明(在头文件里);能够被nib中对象调用的方法称为动作(action),用关键字IBAction标明(在实现文件里)。

12.在实现某个动作或是对象后要对这个动作或是对象后要使用release释放内存。

13.IBOutlet

输出口使用关键字IBOutlet来声明实例变量,并通过这个实例变量来引用nib中的对象;

14.-(IBAction)doSomething:

(id)sender

控制某个对象执行某项动作通过关键字IBAction来声明,通过IBAction告诉interfaceBuilder,此方法是一个操作,且可以被某个控件触发;通常这个操作接受一个参数,该参数被定义为id,名称被指定为sender.(当需要传参数的时候就通过sender来传递,当不需要传参数的时候sender可以不写的);

15.@property(retain,nonatomic)UILabletextArea;

retain是通知编译器向分配给此属性的对象发送一个保留(retain)消息,确保属性的实例变量在被使用过程中不会被从内存中删除;

nonatomic是创建一个互斥访问,避免读和写不同步(非原子性访问);

通过这个属性声明访问来提高执行的效率;(原子性好比如我们去银行存钱,存进去的时候银行账户就会同时增加相应的数额,有一面失败就都回到原来的状态);

16.内存管理理解

①:

程序A里有一段内存被成功申请完成之后,内存计数器就从0变为1

(这个过程是alloc);

②:

然后程序B里也要使用这个内存,那么内存计数器从1变为2

(这个过程是retain);

③:

紧接着程序A不需要这个内存了,那么程序A就把这个内存计数器减1

(这个过程是release);

④:

当系统发现这个内存计数器变为0,那么就调用内存回收程序把这段内存回收(这个过程是dealloc);

17.objc使用消息机制来调用方法,消息就是一个类或者对象可以执行的动作

消息表达式:

[对象或者类名字方法名字:

参数序列];

对象或者类名字:

接收器,是消息的接收者;

方法名字:

参数序列:

要发送的消息(要执行的动作);

代码实现

1.实现图像的移动

NSTimer*timerArrow;

-(IBAction)shoot

{

timerArrow=[NSTimerscheduledTimerWithTimeInterval:

(0.03)target:

selfselector:

@selector(onTimerArrow)userInfo:

nilrepeats:

YES];

}

-(void)onTimerArrow{

NSLog(@"gogogo");

//transform后的参数为图像移动的x,y的距离

arrowView.transform=CGAffineTransformTranslate(arrowView.transform,0,-3.0);

}

2.实现图像的旋转可以有两种实现方式(UIImageView*imageView)

①.使用CGAffineTransformMakeRotation类的类方法CGAffineTransformRotate方法。

imageView.transform=CGAffineTransformRotate(imageView.transform,-0.02);

②.使用CGAffineTransformMakeRotation类的类方法CGAffineTransformMakeRotate方法。

floatangle=0;

angle+=-0.02;

imageView.transform=CGAffineTransformMakeRotation(angle);

3.时间条的读取(UIProgressView*pg)

intprogress=0;

progress++;

//时间条读取的速度,取决于时间的多少(此处为30秒的倒数[1/30])

[pgsetProgress:

progress*0.033];

4.屏幕轻击、触摸事件

①.点击次数

//NSUInteger为无符号的整形

NSUIntegernumTaps=[[touchesanyObject]tapCount];

NSString*tapsMessage=[[NSStringalloc]initWithFormat:

@"%dtapsdetected",numTaps];

②.触摸开始

-(void)touchesBegan:

(NSSet*)toucheswithEvent:

(UIEvent*)event

{

}

③.触摸移动

-(void)touchesMoved:

(NSSet*)toucheswithEvent:

(UIEvent*)event

{

}

④.触摸取消,通常为内存不够用的时候调用

-(void)touchesCancelled:

(NSSet*)toucheswithEvent:

(UIEvent*)event

{

}

⑤.触摸结束

-(void)touchesEnded:

(NSSet*)toucheswithEvent:

(UIEvent*)event

{

}

⑥.轻扫屏幕

.h

UILabel*label;

CGPointmarker;

.m

-(void)touchesBegan:

(NSSet*)toucheswithEvent:

(UIEvent*)event{

UITouch*touch=[touchesanyObject];

marker=[touchlocationInView:

self.view];

}

-(void)touchesMoved:

(NSSet*)toucheswithEvent:

(UIEvent*)event{

UITouch*touch=[touchesanyObject];

CGPointmoved=[touchlocationInView:

self.view];

CGFloatdeltaX=fabsf(marker.x-moved.x);

CGFloatdeltaY=fabsf(marker.y-moved.y);

if(deltaX>=25&&deltaY<=5)

{

label.text=@"yesyesyes";

}

elseif(deltaX<=5&&deltaY>=25)

{

label.text=@"nononono";

}

}

 

5.循环执行一个方法可以有两种实现方法

①.使用NSTimer类的相关方法。

NSTimer*timer;

intcount=0;

-(void)do

{

NSLog(@"Testtimer");

count++;

//10秒之后timer停止

if(count>=10)

{

[timerinvalidate];

}

}

-(void)viewDidLoad{

timer=[NSTimerscheduledTimerWithTimeInterval:

1target:

selfselector:

@selector(do)userInfo:

nilrepeats:

YES];

}

②.使用NSObject类的performSelector:

withObject:

afterDelay方法。

-(void)do

{

NSLog(@"Testtimer");

[selfperformSelector:

@selector(do)withObject:

nilafterDelay:

1];

}

-(void)viewDidLoad{

[selfdo];

}

6.根据选择的按钮,将按钮的title传给标签并显示出来(UILable*status)

NSString*title=[sendertitleForState:

UIControlStateNormal];

NSString*newText=[[NSStringalloc]initWithFormate:

#"youpressthe%@",title];

status.text=newText;

[newTextrelease];

7.点击done关闭键盘(UITextField*nameField)

-(IBAction)nameFieldDoneEditing:

(id)sender;

-(IBAction)nameFieldDoneEditing:

(id)sender

{

[senderresignFirstResponder];

}

点击屏幕关闭键盘

-(IBAction)backgroundClick:

(id)sender;

-(IBAction)backgroundClick:

(id)sender

{

[nameFieldresignFirstResponder];

}

8.通过UISegmentedControl控制UIView(UIView*switch)显示或是隐藏的状态;

-(IBAction)toggleShowHide:

(id)sender

{

UISegmentedControl*segmentedControl=(UISegmentedControl*)sender;

//查询uisegmentcontrol的值

NSIntegersegment=segmentedControl.selectedSegmentIndex;

if(segment==0)

[switchViewsetHidden:

NO];

else

[switchViewsetHidden:

YES];

}

9.UISwitch(UISwitch*soundSwitch)开关的控制

-(IBAction)switchChanged:

(id)sender

{

UISwitch*whichSwitch=(UISwitch*)sender;

BOOLsetting=whichSwitch.isOn;

[SoundSwitchsetOn:

settinganimated:

YES];

}

10.操作表

使用操作表必须符合协议(在.h头文件里的UIViewController后添加);

同时操作表是模式化的(模式化就是程序显示操作表时,程序的其他任何部分都是不可操作的,

必须在操作表上作出选择,才可以执行其他的操作);

-(IBAction)doSomething:

(id)sender

{

UIActionSheet*actionSheet=[[UIActionSheetalloc]initWithTitle:

@"ready?

"

delegate:

self

cancelButtonTitle:

"No"

destructiveButtonTitle:

"Yes"

otherButtonTitle:

@"Woo",@"Cool",nil];

[actionSheetshowInview:

self.view];

[actionSheetrelease];

}

里面的delegate:

self通过将self做为委托参数传递给actionsheet:

didDisMissWithButtonIndex:

actionSheet的方法,当按钮被按下的时候,委托的actionsheet:

didDisMissWithButtonIndex:

actionSheet方法将会被调用;

通过UIActionSheetDelegate的actionSheet:

didDismisswithButtonIndex方法的buttonIndex来指向

操作的索引;

①如果想通过操作表的destructiveButton按钮来执行某项操作;

if(buttonIndex==[actionSheetdestructiveButtonIndex])

{

doSomething;//你要做的操作,显示警报或是别的动作

}

②通过操作表的Woo按钮来执行某项操作;

if(buttonIndex==[actionSheetfirstOtherButtonIndex])

{

doSomething;

}

③通过操作表的cool按钮来执行某项操作;

if(buttonIndex-1==[actionSheetfirstOtherButtonIndex])

{

doSomething;

}

 

11.警报

NSString*msg=nil;

msg=@"Pleaseclickonthegobuttontogetthecoupons.";

UIAlertView*alert=[[UIAlertViewalloc]

initWithTitle:

@"Congratulations"

message:

msg

delegate:

self

cancelButtonTitle:

@"Back"

otherButtonTitles:

@"Go",@"Got",nil];

[alertshow];

[alertrelease];

[msgrelease];

对警报里的按钮做相对应的点击处理(以点击Got按钮显示店铺的宣传网站)

-(void)alertView:

(UIAlertView*)alertViewclickedButtonAtIndex:

(NSInteger)buttonIndex{

switch(buttonIndex){

case0:

//Cancelbutton

break;

case1:

//Go!

button

break;

default:

//Got!

button

[[UIApplicationsharedApplication]openURL:

[NSURLURLWithString:

@"

}

}

12.自动旋转

UIInterfaceOrientationPortrait//直立

UIInterfaceOrientationPortraitUpsideDown//倒立

UIInterfaceOrientationLandscapeLeft//左翻转

UIInterfaceOrientationLandscapeRight//右翻转

如果想设定应用程序是否支持自动翻转,通过interfaceOrientation来设定;(设定后也要手动的调整对应的页面视图的属性)

-(BOOL)shouldAutorotateToInterfaceOrientation:

(UIInterfaceOrientation)interfaceOrientation

{

return(interfaceOrientation==视图朝向);

}

13.切换视图

①.首先添加控制视图的viewController类(负责程序的视图跳转此处定义为switchViewController);

②.添加好程序需要的视图控制类和相对应的xib文件,并在视图xib文件的类特性编辑器里设置好它的基类和视图

输出口;

③.在应用程序委托里写好调用视图跳转的函数

.h

+(Pizza_RockAppDelegate*)App;

.m

+(Pizza_RockAppDelegate*)App{

return(Pizza_RockAppDelegate*)[[UIApplicationsharedApplication]delegate];

}

④.在控制视图的viewController类里,写跳转视图的方法;

-(void)showRockView

{

if(self.pizza_RockViewController==nil)

{

self.pizza_RockViewController=[[Pizza_RockViewControlleralloc]initWithNibName:

@"Pizza_RockViewController"bundle:

nil];

}

[selfremoveAllView];

[self.viewinsertSubView:

self.pizza_RockViewController.viewatIndex:

0];

}

-(void)removeAllView

{

for(NSIntegeri=0;i<[self.view.subViewscount];i++)

{

[[self.view.subviewsobjectAtIndex:

i]removeFromSuperview];

}

}

⑤.在视图控制类里调用应用程序委托里写好的函数来完成视图的跳转

-(IBAction)buttonClick:

(id)sender

{

[[Pizza_RockAppDelegateApp].switchViewControllershowRockView];//showRockView为在控制视图跳转的类里定义好的方法

[labelremoveFromSuperview];

}

14.建立工具栏(TabBarController)

①.创建控制视图的viewController类以及控制视图所对应的视图xib文件(工具栏有几个标签控制器,则创建几个控制视图类文件);

②.设置视图nib对应的viewController类,并设置好File'sOwner的输出口为对应的view;

③.在应用程序委托里创建UITabBarController的实例;

④.在MainWindow.xib里,添加一个TabBarController,并在属性检查器里添加工具栏所需要的标签控制器,并设置好标签控制器

对应的标题名称、NIBNAME、图标;

15.表视图

表视图从遵循UITableViewDelegate协议的对象中获取配置数据;

从遵循UITableViewDataSource协议的对象获得行数据;

①.查看指定分区并返回表分区中的行数;(NSArray*listData)

-(NSInteger)tableView:

(UITableView*)tableViewnumberOfRowsInSection:

(NSInteger)section

{

return[self.listDatacount];

}

②.根据声明的字符串键值来绘制表视图中的行

-(UITableViewCell*)tableView:

(UITableView*)tableViewcellForRowAtIndexPath:

(NSIndexPath*)indexPath

{

//声明表单元里的键值(标识符)

staticNSString*SimpleTableIdentifier=@"SimpleTableIdentifier";

//根据这个声明的键值返回可重用的表视图标识符

UITableViewCell*cell=[tableViewdequeueReusableCellWithIdentifier:

SimpleTableIdentifier];

if(cell==nil)

{

cell=[[[UITableViewCellalloc]initWithFrame:

CGRectZeroreuseIdentifier:

SimpleTableIdentifier]autorelease];

}

NSUIntegerrow=[indexPathrow];

cell.text=[listDataobjectAtIndex:

row];

returncell;

}

③.为指定的行添加图像

//0为要添加图像的行数的下标

if([indexPathrow]==0)

{

UIImage*image=[UIImageimageNamed:

@"beef.png"];

cell.image=image;

}

④.设置表视图的缩进级别(树状的表视图以后弄清楚)

-(NSInteger)tableView:

(UITableView*)tableViewindentationLev

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1