2013-04-13 133 views
0

我有2個ViewControllers,ViewController_A和ViewController_B。 ViewController_A有一個帶有doSlider方法的滑塊,如下所示。更新滑塊值

- (void)doSlider:(float)value{ 
    [viewController_B getValue:[slider_1 value]]; 
} 

ViewController_B了getValue方法如下。

- (void)getValue:(float)value{ 
    width = value; 
    NSLog(@"getValue %f", width); 
} 

當我在ViewController_A中拖動滑塊時,ViewController_B會打印出寬度值。但它似乎只在getValue方法中可用。我可以將寬度值傳遞給ViewController_B中的其他方法,例如touchesMoved。謝謝。

+0

你爲什麼不把width設置爲viewController_B的一個屬性。其實,在我看來,這就是你正在做的事情,但也許我錯過了一些東西。 – Josiah

回答

0

是的。一旦你得到滑動值與[slider_1 value]你可以使用任何你喜歡的方式。當您將值傳遞給getValue:並分配給width時,您可以隨意使用width

+0

我用「寬度」在touchesMoved中設置畫筆大小,但它始終爲零。如何通過「寬度」touchesMoved? – user2239950

+0

'touchesMoved:withEvent'與'double'數字沒有多大關係。它必須是你的代碼相關的參數傳遞給'touchesMoved:withEvent'這是責怪。 – GoZoner

+0

你的意思是不可能將參數傳遞給touchesMoved? – user2239950