我正在使用zBar SDK,一旦qr代码检测到委托将运行,在此委托中我定义了myView并将其用作相机上的叠加层,其中包含有关该qr代码的信息。 在myView里面有一个调用方法的按钮(testAction)但是在这个方法中我无法访问我在委托中定义的任何对象,如何在testAction里面访问myView和对象?
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
UIView *myView;
CGRect frame= CGRectMake(0, 0, 320, 428);
myView=[[UIView alloc] initWithFrame:frame];
myView.backgroundColor=[UIColor greenColor];
myView.alpha=0.7;
CGRect labelFrame = CGRectMake( 0, 0, 500, 30 );
UILabel* myLabel = [[UILabel alloc] initWithFrame: labelFrame];
[myLabel setTextColor: [UIColor orangeColor]];
NSString *combined = [NSString stringWithFormat:@"%@%@", @"Title: ", symbol.data];
myLabel.text=combined;
UIButton * myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(10, 50, 100, 50);
myButton.tag = 121;
[myButton setTitle:@"Do Something" forState:UIControlStateNormal];
[myButton setBackgroundImage:nil forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(testAction:) forControlEvents:UIControlEventTouchUpInside];
//[button setBackgroundColor:red];
[myView addSubview: myLabel];
[myView addSubview: myButton];
reader.cameraOverlayView=myView;
}
- (void)testAction: (id)sender{
//my issue is here
}
答案 0 :(得分:0)
制作属性。
在你的界面中有:
@property (strong, nonatomic) UIView *myView;
@property (strong, nonatomic) UILabel *myLabel;
@property (strong, nonatomic) UIButton *myButton;
在你的委托方法中:
CGRect frame= CGRectMake(0, 0, 320, 428);
self.myView=[[UIView alloc] initWithFrame:frame];
self.myView.backgroundColor=[UIColor greenColor];
self.myView.alpha=0.7;
CGRect labelFrame = CGRectMake( 0, 0, 500, 30 );
self.myLabel = [[UILabel alloc] initWithFrame: labelFrame];
self.myLabel.textColor = [UIColor orangeColor];
self.myLabel.text = [NSString stringWithFormat:@"%@%@", @"Title: ", symbol.data];
self.myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.myButton.frame = CGRectMake(10, 50, 100, 50);
self.myButton.tag = 121;
[self.myButton setTitle:@"Do Something" forState:UIControlStateNormal];
[self.myButton setBackgroundImage:nil forState:UIControlStateNormal];
[self.myButton addTarget:self action:@selector(testAction:) forControlEvents:UIControlEventTouchUpInside];
[self.myView addSubview:self.myLabel];
[self.myView addSubview:self.myButton];
reader.cameraOverlayView = self.myView;
最后在你的行动中:
- (void)testAction: (id)sender
{
// self.myView, self.myLabel and self.myButton are all available.
}