目前,我正在创建一个项目,要求用户在与应用程序进行交互时输入日期和时间,但我对标准UIKit UIDatePicker
的外观感到不满意建立我自己的。
目前我的功能正常,多个UITableView
持有日,小时,分钟和可选的AM / PM(如果用户指定非24小时)。
我坚持的一点就是让tableViews在常规UIDatePicker
中循环选项。有没有什么技术可以用UITableView
创建这种效果?
我还简要介绍了UIPickerView
,但我不确定循环的功能是否比使用tableView更容易/更难。我知道那些设计可以用
- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated
例如,Clear的最新更新有一个自定义日期选择器实现:
答案 0 :(得分:0)
我认为这不是标准的做法。也许你可以检查tableview的scrollView内容偏移并调整它以跳转到你想要的位置。
为了使其正常工作,您无法看到需要复制单元格数量的跳转。
不确定它是否是最佳方式,但此代码有效,请尝试:
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.dataSource = self;
self.tableView.delegate = self;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return numberOfCells*2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"myCell"];
if(!cell) {
cell = [[UITableViewCell alloc] init];
}
cell.textLabel.text = [NSString stringWithFormat:@"Cell N: %d", indexPath.row%numberOfCells];
return cell;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if((scrollView.contentOffset.y+scrollView.frame.size.height)>=scrollView.contentSize.height) {
scrollView.contentOffset = CGPointMake(0, scrollView.contentSize.height/2-scrollView.frame.size.height);
}
if(scrollView.contentOffset.y<=0) {
scrollView.contentOffset = CGPointMake(0, scrollView.contentSize.height/2);
}
}