我試圖創建自定義UIPickerView,類似下面..:自定義UIPickerView
http://img824.imageshack.us/img824/3015/pickercustom.png
例如: 從 「8h15」 到 「12h15」
我這個完全失明概念。
請幫助我...任何想法,主意將不勝感激。
我試圖創建自定義UIPickerView,類似下面..:自定義UIPickerView
http://img824.imageshack.us/img824/3015/pickercustom.png
例如: 從 「8h15」 到 「12h15」
我這個完全失明概念。
請幫助我...任何想法,主意將不勝感激。
它可能不是一個datepicker,它可能是UIPickerView的實例已經被配置這種方式:
你不能這樣做,用的UIDatePicker。改爲使用PickerView。您可以連續顯示「8h15」至「12h15」。有關快速教程,請參閱此link。
您可以使用帶3段的UIPickerView控件。填充每個段上的預定義數據。
您將不得不自定義UIPickerView。要選擇小時數,您應該創建兩個包含您想要的值/標題的數組。
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(22, 170, 275, 217)];
pickerView.delegate = self;
pickerView.dataSource = self;
pickerView.showsSelectionIndicator = YES;
pickerView.opaque = NO;
[self.view addSubview:pickerView];
[pickerView release];
,並委託方法
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
return 3;
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent: (NSInteger)component {
NSInteger count = 0;
switch (component) {
case 0:
count = [arrayHours1 count];
break;
case 1:
count = 1;
case 2:
count = [arrayHours2 count];
break;
}
return count;
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
NSString *title = @"";
switch (component) {
case 0:
title = [arrayHours1 objectAtIndex:row];
break;
case 2:
title = [arrayHours2 objectAtIndex:row];
break;
}
return title;
}
希望這有助於!
您可以檢查: -
代碼在這裏
的NSDate * choosen = datePickerView。日期;
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"yyyy-MM-dd"];
//[formatter setDateFormat:@"dd-MM-yyyy"];
NSString *weekday = [formatter stringFromDate:choosen];
invoiveDateTxtFld.text = [[NSString alloc] initWithFormat:@"%@", weekday];
我認爲它的自定義pikerview不是日期匹配。 – 2012-04-12 09:30:57