现在的位置: 首页 > 综合 > 正文

07选取器总结

2012年08月08日 ⁄ 综合 ⁄ 共 1760字 ⁄ 字号 评论关闭

选取器载入图像时要包装成UIImageView
UIPickerViewDataSource,UIPickerViewDelegate
 -(NSInteger)numberOfComponentsInPickerView:(UIPickerView* )pickerView;
 -(NSInteger)pickerView:(UIPickerView*)pickerView numberOfRowsInComponent:(NSInteger)component;
 

(required)选取器中的元素
//字符串  -(NSString*)pickerView:(UIPickerView*)pickerView
   titleForRow:(NSInteger)row
   forComponent:(NSInteger)component;

//图像    -(UIView*)pickerView:(UIPickerView*)pickerView
   viewForRow:(NSInteger)row
   forComponent:(NSInteger)component;
当选取器有两个组件(即有两个框)且右边框的内容随左边框的内容变换而变换时,实现
 -(void)pickerView:(UIPickerView*)pickerView
  didSelectRow:(NSInteger)row
  inComponent:(NSInteger)component;
如果要调整两个组件的大小则
-(CGFloat)pickerView:(UIPickerView*)pickerView widthForComponent:(NSInteger)component;

注意:IB中需配置pickerView的attribute 中的dataSource与Delegate都连向File's Owner

UIPickerView 方法:-(NSInteger)selectedRowInComponent:(int);
寻找路径并载入
NSBundle *bundle=[NSBundle mainBundle];
NSString *path=[bundle pathForResource:@"文件名" ofType:@"扩展名"];
NSDictionary *d=[[NSDictionary alloc]initWithContentsOfFile:path];

排序数组
NSArray *array;
NSArray *sorted=[array sortedArrayUsingSelector:@selector(compare:)];

得到字典的全部键
NSArray *arr=[dictionary allKeys];

选择选取器的特定组件特定行并实现动画
[picker selectedRow:row inComponent:component animated:YES];
[picker reloadComponent:component];

图像导入
UIImage *image=[UIImage imageName:@"全部文件名"];
UIImageView *imageView=[[UIImageView alloc]initWithName:image];

键值对
[self setValue:NSObject* forKey:@"..."];

随机数生成
int i=random()%n;

视频音频导入
#import<AudioToolbox/AudioToobox.h>
第一:记得加入framework
NSString *path=[[NSBundle mainBundle]pathForResource:@"文件名" ofType:@"扩展名"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileWithPath:path],&soundID);
AudioServicesPlaySystemSound(soundID);

自定义调用方法函数
[self performSelector:@selector(函数名) withObject:nil afterDelay:时间];

 

抱歉!评论已关闭.