2016.8.3
在使用UIPickerView的時(shí)候扬跋,多個(gè)地方需要顯示不同數(shù)據(jù)的picker,但是在不同的地方picker的行title會(huì)顯示成第一個(gè)picker的數(shù)據(jù)蕾域,這時(shí)要在picker出現(xiàn)的方法里刷新一下picker的數(shù)據(jù)买喧,即
[self.durationPickerreloadComponent:0];
durationPicker的應(yīng)該是繼承于UIPickerView的一個(gè)view
[selfpickerView:self.durationPickerdidSelectRow:0inComponent:0];//實(shí)現(xiàn)默認(rèn)選中第一行的點(diǎn)擊方法搔啊,將第一行的title傳給控制器
將picker加在一個(gè)背景view上姨俩,點(diǎn)擊view的時(shí)候picker可以消失
UITapGestureRecognizer*tap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(removeView:)];
[_viewaddGestureRecognizer:tap];
[[UIApplicationsharedApplication].keyWindowaddSubview:_view];
[UIViewanimateWithDuration:0.3animations:^{
self.frame=CGRectMake(0,_view.frame.size.height-self.frame.size.height,ScreenFullWidth,self.frame.size.height);
}];
- (void)removeView:(UITapGestureRecognizer*)tap {
CGPointpoint = [taplocationInView:_view];
//是否包含某個(gè)rect里的點(diǎn)
if(CGRectContainsPoint(self.frame, point)) {
}else{
[selfremovePicker];
}
}
- (void)removePicker {
[UIViewanimateWithDuration:0.5animations:^{
self.frame=CGRectMake(0,self.frame.origin.y+self.frame.size.height,ScreenFullWidth,self.frame.size.height);
}completion:^(BOOLfinished) {
[_viewremoveFromSuperview];
[self.rowsArrremoveAllObjects];
}];
}
如果有兩列蘸拔,不要設(shè)置默認(rèn)選中的行师郑,如
[selfpickerView:self.pickerdidSelectRow:0inComponent:0];
如果加上這句話,再次顯示picker的時(shí)候第二列顯示的數(shù)據(jù)會(huì)是第一列第一行對(duì)應(yīng)的那個(gè)數(shù)組调窍,不會(huì)顯示上次選中的行
[selfpickerView:self.durationPickerdidSelectRow:0inComponent:0];//實(shí)現(xiàn)默認(rèn)選中第一行的點(diǎn)擊方法宝冕,將第一行的title傳給控制器