OK、これが私の質問の例です。最初の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;
...
}
両方のコントローラーにアクションを与える方法を知っている人はいますか?
まことにありがとうございます!