UISlider如何设置初始值
我对 iPhone 开发工作还很陌生,我正在一家公司处理一些现有的代码。我试图设置初始值的 uislider 实际上位于 UITableViewCell 中,并且是一个自定义控件。我在想,在单元格初始化中,
cell = (QuantitiesCell *)[self loadCellWithNibName:@"QuantitiesCell" forTableView:ltableView withStyle:UITableViewCellStyleDefault];
我可以调用类似的东西,
((QuantitiesCell *)cell).value = 5;
实际的 QuantitiesCell 类具有成员值和以下函数,
-(void)initCell;{
if (listOfValues == nil) {
[self initListOfValues];
}
quantitiesSLider.maximumValue = [listOfValues count]-1;
quantitiesSLider.minimumValue = 0;
quantitiesSLider.value = self.value;
}
-(void)initListOfValues;{
listOfValues = [[NSMutableArray alloc] initWithCapacity:10];
int j =0;
for (float i = minValue; i <= maxValue+increment; i=i+increment) {
[listOfValues addObject:[NSNumber numberWithFloat: i]];
if (i == value) {
quantitiesSLider.value = j;
}
j++;
}
}
就像我说的那样,我对此很陌生,所以如果我需要发布更多代码来显示正在发生的事情要获得帮助,请告诉我,
此滑块始终默认为 1,滑块范围通常为 1-10,我想将其设置为我要编辑的项目的特定值。
I'm pretty new at this iphone dev stuff and i'm working on some existing code at a company. The uislider i'm trying to set the initial value on is actually in a UITableViewCell and is a custom control. I was thinking in the cell init
cell = (QuantitiesCell *)[self loadCellWithNibName:@"QuantitiesCell" forTableView:ltableView withStyle:UITableViewCellStyleDefault];
i could just call something like
((QuantitiesCell *)cell).value = 5;
The actual QuantitiesCell class has the member value and the following functions
-(void)initCell;{
if (listOfValues == nil) {
[self initListOfValues];
}
quantitiesSLider.maximumValue = [listOfValues count]-1;
quantitiesSLider.minimumValue = 0;
quantitiesSLider.value = self.value;
}
-(void)initListOfValues;{
listOfValues = [[NSMutableArray alloc] initWithCapacity:10];
int j =0;
for (float i = minValue; i <= maxValue+increment; i=i+increment) {
[listOfValues addObject:[NSNumber numberWithFloat: i]];
if (i == value) {
quantitiesSLider.value = j;
}
j++;
}
}
like i said, i'm pretty new at this so if i need to post more of the code to show whats going to get help, let me know,
This slider always is defaulting to 1, the slider ranges usually from 1-10, and i want to set it to a specific value of the item i'm trying to edit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的链接正确(您已在 Interface Builder 中建立连接),则设置 slider.value 是正确的方法。如果您在代码中创建了 UISlider,您所要做的就是设置 value 属性。如果这不起作用,那么首先请确保该对象是“活动的”(正确分配,未释放,未超出范围等),其次确保您设置 slider.value 的函数实际上正在被调用。
如果您正在使用 Interface Builder,并且不确定如何将滑块连接为
IBOutlet
,您应该查看 iTunes University - 搜索“CS193P”以查找斯坦福大学的一些精彩视频。第一对将带您建立这些联系。如果使用 IB 并且您尚未建立连接 - 什么都不会发生。Setting slider.value is the correct way if your linkage is correct (you have made the connections in Interface Builder). If you have created a UISlider in code, all you have to do is set the value property. If that is not working then be sure firstly that the object is "live" (correctly allocated, not released, not out of scope etc.) and secondly that the functions in which you set slider.value are actually being called.
If you are using Interface Builder and are not sure of how to connect your slider as an
IBOutlet
, you should check out iTunes University - search for "CS193P" to find some excellent videos from Stanford University. The first couple will take you through making those connections. If using IB and you have not made the connection - nothing will happen.PS 我有相同的发行者 - 您需要先添加 UISlide 视图,然后才能更改值。
PS I had the same issuer - you need to add the UISlide view first then you can change the value.