iPhone SDK:在表格视图中添加 UISlider 和 UISwitch 仅在触摸滑块时崩溃?
好的,这是我的问题 敌人的例子,我在前3个单元格的accessoryView中创建一个UISwitch
theSwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
[cell addSubview:theSwitch];
cell.accessoryView = theSwitch;
,并在接下来的3个单元格中添加2个滑块
theSlider = [[[UISlider alloc] initWithFrame:CGRectMake(174,12,120,23)] autorelease];
theSlider.maximumValue=99;
theSlider.minimumValue=0;
[cell addSubview:theSlider];
cell.accessoryView = theSlider;
,之后,我添加开关和滑块的操作,
[(UISwitch *)cell.accessoryView addTarget:self action:@selector(switchToggled:) forControlEvents:UIControlEventValueChanged];
[(UISlider *)cell.accessoryView addTarget:self action:@selector(sliderValueChange:) forControlEvents:UIControlEventValueChanged];
如果只在单元格中添加开关,它就可以工作
我认为这可能是我的@selector (switchToggled:) 和 @selector(sliderValueChange:)
问题。
如果我切换 UISwitch ,它不会崩溃
,但如果我触摸任何滑块,它就会崩溃并收到消息:“[UISlider isOn]:无法识别的选择器发送到实例”
这是我关于
- (void)switchToggled:(id)sender{
UISwitch *theSwitch = (UISwitch *)sender;
UITableViewCell *cell = (UITableViewCell *)theSwitch.superview;
UITableView *tableView = (UITableView *)cell.superview;
NSIndexPath *indexPath = [tableView indexPathForCell:cell];
if(theSwitch.on) {
...
}
else {
...
}
}
sliderValueChange
的无效一切都与
- (void)sliderValueChange:(id)sender{
UISlider *theSlider = (UISlider *)sender;
UITableViewCell *cell = (UITableViewCell *)theSlider.superview;
UITableView *tableView = (UITableView *)cell.superview;
...
}
有谁知道如何向两个控制器执行操作吗?
非常感谢!
OK,here is my question
foe example,I create a UISwitch in the first 3 cell's accessoryView
theSwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];
[cell addSubview:theSwitch];
cell.accessoryView = theSwitch;
and add 2 slider in next 3 cells
theSlider = [[[UISlider alloc] initWithFrame:CGRectMake(174,12,120,23)] autorelease];
theSlider.maximumValue=99;
theSlider.minimumValue=0;
[cell addSubview:theSlider];
cell.accessoryView = theSlider;
after that , I add action to switch and slider
[(UISwitch *)cell.accessoryView addTarget:self action:@selector(switchToggled:) forControlEvents:UIControlEventValueChanged];
[(UISlider *)cell.accessoryView addTarget:self action:@selector(sliderValueChange:) forControlEvents:UIControlEventValueChanged];
It's works if only add switch in cell
I think this is maybe my @selector(switchToggled:)
and @selector(sliderValueChange:)
issue.
if I switch the UISwitch ,It won't crash
but if I touch any slider ,it crash and got message :"[UISlider isOn]: unrecognized selector sent to instance"
here is my void about
- (void)switchToggled:(id)sender{
UISwitch *theSwitch = (UISwitch *)sender;
UITableViewCell *cell = (UITableViewCell *)theSwitch.superview;
UITableView *tableView = (UITableView *)cell.superview;
NSIndexPath *indexPath = [tableView indexPathForCell:cell];
if(theSwitch.on) {
...
}
else {
...
}
}
the sliderValueChange
all most the same as
- (void)sliderValueChange:(id)sender{
UISlider *theSlider = (UISlider *)sender;
UITableViewCell *cell = (UITableViewCell *)theSlider.superview;
UITableView *tableView = (UITableView *)cell.superview;
...
}
Does anyone knows how to give an action to both controller ?
Great Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新
注释之后,这是您应该使用的通用选择器。
注意:使用此选择器您只需调用 addTarget 一次。
UPDATE
After the comments, here is a general selector you should use.
Note: you will need to call addTarget only once using this selector.