2013-06-12 8 views
-1

qr 코드가 대리자가 실행되는 것을 감지하면 qrar SDK를 사용합니다.이 대리자 내에서 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

속성을 만듭니다. 사용자 인터페이스에서

이있다 : 당신의 대리자 메서드에서

@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. 
} 
+0

OMG 때때로 뇌 그냥 잠! – user2211254