
所以我的问题是,有没有示例代码,有人写了一个CustomUIPickerVIEw几个小时,最小和秒,我可以纳入我的项目? UIDatePicker有一个很好的叠加时间&在用户旋转拨盘时,打开保留的文本。如果有人在他们的自定义选择器中也添加了这将是很好的。我不喜欢从头开始编写一个自定义的UIPickerVIEw。谢谢。
解决方法 Alrighty的人,这里是你的UIPickerVIEw获得几小时/分钟/秒的代码。您可以添加3个标签,策略性地将它们放置在选择器上。我也附上了一张照片。如果你喜欢这个答案,做点评吧!良好的开发者分享知识,不像某些人所暗示的那样隐藏。有乐趣的编码!
在你的标题.h文件放这个
@interface v1AddtableVIEwController : UItableVIEwController{ IBOutlet UIPickerVIEw *pickerVIEw; NSMutableArray *hoursArray; NSMutableArray *minsArray; NSMutableArray *secsArray; NSTimeInterval interval;}@property(retain,nonatomic) UIPickerVIEw *pickerVIEw;@property(retain,nonatomic) NSMutableArray *hoursArray;@property(retain,nonatomic) NSMutableArray *minsArray;@property(retain,nonatomic) NSMutableArray *secsArray; 在你的.m文件中放这个
@synthesize pickerVIEw;@synthesize hoursArray;@synthesize minsArray;@synthesize secsArray;@synthesize interval;- (voID)vIEwDIDLoad{ [super vIEwDIDLoad]; //initialize arrays hoursArray = [[NSMutableArray alloc] init]; minsArray = [[NSMutableArray alloc] init]; secsArray = [[NSMutableArray alloc] init]; Nsstring *strVal = [[Nsstring alloc] init]; for(int i=0; i<61; i++) { strVal = [Nsstring stringWithFormat:@"%d",i]; //NSLog(@"strVal: %@",strVal); //Create array with 0-12 hours if (i < 13) { [hoursArray addobject:strVal]; } //create arrays with 0-60 secs/mins [minsArray addobject:strVal]; [secsArray addobject:strVal]; } NSLog(@"[hoursArray count]: %d",[hoursArray count]); NSLog(@"[minsArray count]: %d",[minsArray count]); NSLog(@"[secsArray count]: %d",[secsArray count]);}//Method to define how many columns/dials to show- (NSInteger)numberOfComponentsInPickerVIEw:(UIPickerVIEw *)pickerVIEw{ return 3;}// Method to define the numberOfRows in a component using the array.- (NSInteger)pickerVIEw:(UIPickerVIEw *)pickerVIEw numberOfRowsInComponent :(NSInteger)component { if (component==0) { return [hoursArray count]; } else if (component==1) { return [minsArray count]; } else { return [secsArray count]; }}// Method to show the Title of row for a component.- (Nsstring *)pickerVIEw:(UIPickerVIEw *)pickerVIEw TitleForRow:(NSInteger)row forComponent:(NSInteger)component{ switch (component) { case 0: return [hoursArray objectAtIndex:row]; break; case 1: return [minsArray objectAtIndex:row]; break; case 2: return [secsArray objectAtIndex:row]; break; } return nil;}-(IBAction)calculateTimeFromPicker{ Nsstring *houRSStr = [Nsstring stringWithFormat:@"%@",[hoursArray objectAtIndex:[pickerVIEw selectedRowInComponent:0]]]; Nsstring *minsstr = [Nsstring stringWithFormat:@"%@",[minsArray objectAtIndex:[pickerVIEw selectedRowInComponent:1]]]; Nsstring *secsstr = [Nsstring stringWithFormat:@"%@",[secsArray objectAtIndex:[pickerVIEw selectedRowInComponent:2]]]; int hoursInt = [houRSStr intValue]; int minsInt = [minsstr intValue]; int secsInt = [secsstr intValue]; interval = secsInt + (minsInt*60) + (hoursInt*3600); NSLog(@"hours: %d ... mins: %d .... sec: %d .... interval: %f",hoursInt,minsInt,secsInt,interval); Nsstring *totalTimeStr = [Nsstring stringWithFormat:@"%f",interval];} 总结 以上是内存溢出为你收集整理的iphone – UIPickerView看起来像UIDatePicker,但与秒全部内容,希望文章能够帮你解决iphone – UIPickerView看起来像UIDatePicker,但与秒所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)