English 中文(简体)
从次调查中检索价值 目标c
原标题:Retrieving values from subviews Objective-c

I have created a subclass of a UIView which is a rotating wheel. This wheel is part of another UIView which has an image in the top right corner. When the wheel is turned, in the touchMoved function the right most item is returned (its number). I need to then change the parent s image automatically when the subview is turned (when the number is returned)

假设我有这个数目,那么我怎么会把这个数目退回给父母,或者从次表上改变形象(在父母意见中)。

增 编

最佳回答

第一,制定一份议定书,界定你希望在你的透视中呼吁的方法:

@protocol wheelViewDelegate {
   -(void)doSomething;
}

您对执行该议定书的看法:

@interface superView:UIView<wheelViewDelegate> {
...
}
...
@end

此外,你显然需要采用<代码>doSomething方法。

The UIView, which contained the wheel need to be a sub-class of UIView and hold the delegation, as this:

@interface WheelView : UIView {
id<wheelViewDelegate> delegate;
...
}
@propery (nonatomic, assign) id<wheelViewDelegate> delegate;
...
@end

Don tabe to @synthesize id; in You implementation.

如今,您可从次概略中点击doSomething:

[self.delegate doSomething];

EDIT:

奥凯,我认为这是显而易见的,但当然,你需要把代表安排在这样的位置上:

//In your superView:
WheelView* wv = [WheelView initSomeHow];
wv.delegate = self;
问题回答

<>Phlibbo中提到的代表方法就是这样做的一种方式。 由于您的习俗观点分流更像是一种具有价值的控制,因此,我将分级<条码>查询/编码>,而不是<条码>查询<条码>,并使用<条码>查询。

在您的习俗分流中,这一数值已经发生变化(可能载于您的 依次:有:):

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [self sendActionsForControlEvents:UIControlEventValueChanged];
}

现在观察贵方控制器的价值变化,让控制者在另一种观点中更新形象。

- (void) viewDidLoad {
    [wheelControl addTarget:self action:@selector(wheelValueChanged:) forControlEvents:UIControlEventValueChanged];
}

- (void) wheelValueChanged:(id)sender {
    // update your image based on the wheel value of sender (wheelControl in this case).
}




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签