Xcode Cocoa 默认选择器动画不适用于 iOS 应用程序
Posted
技术标签:
【中文标题】Xcode Cocoa 默认选择器动画不适用于 iOS 应用程序【英文标题】:Xcode Cocoa default picker animation not animating for iOS app 【发布时间】:2015-05-09 05:27:38 【问题描述】:所以我已经按照Default Picker Value iphone 这篇帖子所说的所有内容进行操作,但我似乎无法让我的选择器工作。
这是我的 .m sn-p:
- (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.arrPercent = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",@"32",@"33",@"34",@"35",@"36",@"37",@"38",@"39",@"40",@"41",@"42",@"43",@"44",@"45",@"46",@"47",@"48",@"49",@"50"];
self.arrPeople = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20"];
self.percent = [NSNumber numberWithInt:15];
self.people = [NSNumber numberWithInt:5];
self.strSubTotal = @"";
self.myPicker.dataSource = self;
self.myPicker.delegate = self;
- (void)viewDidAppear:(BOOL)animated
[super viewDidAppear:animated];
//[self.myPicker selectRow:self.percent.integerValue inComponent:0 animated:YES];
[self.myPicker selectRow:5 inComponent:0 animated:YES];
[self.myPicker selectRow:5 inComponent:1 animated:YES];
[self.myPicker reloadAllComponents]; // tried commenting out this line with no luck
这是我的 .h sn-p:
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface ViewController : UIViewController <UIPickerViewDataSource,UIPickerViewDelegate>
@property (nonatomic,strong) NSArray *arrPercent;
@property (nonatomic,strong) NSArray *arrPeople;
@property (strong, nonatomic) IBOutlet UIPickerView *myPicker;
@property (strong, nonatomic) NSString *strSubTotal;
@property (strong, nonatomic) NSNumber *percent;
@property (strong, nonatomic) NSNumber *people;
@end
这是代表的东西,我想...
// returns the number of 'columns' to display.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
return 2;
// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component
if(component== 0)
return [self.arrPercent count];
else
return [self.arrPeople count];
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
if(component == 0)
return [NSString stringWithFormat:@"%@%@", [self.arrPercent objectAtIndex:row], @"%"];
else
return [self.arrPeople objectAtIndex:row];
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
if(component == 0)
self.percent = [self.arrPercent objectAtIndex:row];
else
self.people = [self.arrPeople objectAtIndex:row];
[self updateSubTotal:-3];
当我启动模拟器时,选择器不会动画到我告诉它的位置。我做错什么了吗?请帮忙!
【问题讨论】:
你看到了什么?选择器是否已填充? 选择器的委托方法在哪里?可以发一下吗? 我已经用我的更多代码更新了这个问题。谢谢! 你还没有说它做什么做什么。它是否显示第一行的值?它是否显示了第 5 行的数据,但没有对其进行动画处理? @rdelmar 我想通了。稍后会发布答案! 【参考方案1】:事实证明,错误是由于某种原因,UI 中的选择器之间的连接与代码断开了连接。在将选取器从 UI 拖到 .h 文件时,我必须按住 Control 键。
我看到这个是因为我注意到 .h 文件中的方法声明旁边有一个小的“空按钮图标”。一旦 Xcode 明白选择器是由一段代码控制的,一切都会按预期工作。
非常感谢!
【讨论】:
以上是关于Xcode Cocoa 默认选择器动画不适用于 iOS 应用程序的主要内容,如果未能解决你的问题,请参考以下文章
UITapGestureRecognizer 不适用于 UIView 动画
OpenGL 代码适用于 Windows 但不适用于 Mac