我在项目中添加了MTCircularSlider pod。 我的viewController如下所示:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
USE ieee.numeric_std.ALL;
ENTITY ccalctb IS
END ccalctb;
ARCHITECTURE behavior OF ccalctb IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT dcalc
PORT(
k : IN std_logic_vector(7 downto 0);
o : IN std_logic_vector(7 downto 0);
e : IN std_logic_vector(7 downto 0);
d : OUT std_logic_vector(7 downto 0);
clk : IN std_logic
);
END COMPONENT;
--Inputs
signal k : std_logic_vector(7 downto 0) := (others => '0');
signal o : std_logic_vector(7 downto 0) := (others => '0');
signal e : std_logic_vector(7 downto 0) := (others => '0');
signal clk : std_logic := '0';
--Outputs
signal d : std_logic_vector(7 downto 0);
-- Clock period definitions
constant clk_period : time := 10 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: dcalc PORT MAP (
k => k,
o => o,
e => e,
d => d,
clk => clk
);
-- Clock process definitions
clk_process :process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 100 ns.
wait for 100 ns;
k<=x"07";
o<=x"08";
e<=x"07";
wait for clk_period*10;
-- insert stimulus here
wait;
end process;
END;
我的用户界面如下:
我的rootView如下:
我正在使用以下代码在TabBar上加载此viewController:
class ViewController: UIViewController {
@IBOutlet var slider: MTCircularSlider!
@IBOutlet var sliderLabel: UILabel!
let temperatureArray = ["7.5","8.0","8.5","9.0","9.5","10.0","10.5","11.0","11.5","12.0","12.5","13.0","13.5","14.0","14.5","15.0","15.5","16.0","16.5","17.0","17.5","18.0","18.5","19.0","19.5","20.0","20.5","21.0","21.5","22.0","22.5","23.0","23.5","24.0","24.5","25.0","25.5","26.0","26.5","27.0","27.5","28.0","28.5"]
override func viewDidLoad() {
super.viewDidLoad()
self.slider.addTarget(self, action: #selector(valueChange), for: .valueChanged)
}
@objc func valueChange() {
//Slider value change
let value = Float(slider.value)
let numberString = String(value)
let numberComponent = numberString.components(separatedBy :".")
let integerNumber = Int(numberComponent [0])!
let fractionalString = numberComponent[1].prefix(1)
var fractionalNumber:Int = Int(fractionalString)!
if fractionalNumber >= 5 {
fractionalNumber = 5
}
else {
fractionalNumber = 0
}
let temperature = String(integerNumber) + "." + String(fractionalNumber)
if temperature == "7.5" {
sliderLabel.text = NSLocalizedString("min", comment: "")
}
else if temperature == "28.5" {
sliderLabel.text = NSLocalizedString("max", comment: "")
}
else {
sliderLabel.text = temperature + " °C"
}
if temperatureArray.contains(temperature) {
let index = temperatureArray.firstIndex(of: temperature)
print(index!)
}
}
}
当我加载viewController时,通常意味着按下此View时它可以正常工作。但是,当我在选项卡上单击添加时,则不会调用我的函数valueChange()。请给我任何解决方案。
答案 0 :(得分:0)
尝试
slider.addTarget(self, action: #selector(ViewController.handle(_:)), for: . valueChanged)
// Handle Action
@objc func handle(_ sender: AnyObject) {
}
答案 1 :(得分:-1)
如GitHub - MTCircularSlider参考中给出的,ValueChange方法具有一个参数。可能是发送方参数。请在下面查看其代码。
self.slider?.addTarget(self, action: Selector("valueChange:"), forControlEvents: .ValueChanged)
但是您的代码似乎丢失了它。你可以尝试这样的事情吗?
@objc
func valueChange(sender: AnyObject) {
}
请让我知道这会有所帮助。