2012-04-22 4 views
0

두 개의 버튼 (버튼 추가 및 삭제)을 그려야하는 UIPopoverViewController를 시작합니다. UIPopover에 대한 ContentViewController는 UIPopoverViewController가 시작되기 직전에 설정된 outputJackView이라는 속성을 가지고 있습니다. 이 속성은 버튼을 올바르게 그리는 데 필요합니다. 문제는 첫 번째 버튼이 하위보기로 추가 된 직후인데 outputJackView은 null로 설정됩니다. 여기 하위 뷰를 추가 한 후에 속성이 null입니다.

는 UIPopoverViewController 대한 ContentViewController이다 CableConnectionMenuController.m

#import "CableConnectionMenuController.h" 
#import "JackView.h" 
#import "CableDisconnectButton.h" 

@implementation CableConnectionMenuController 

@synthesize delegate; 
@synthesize outputJackView; 

...

CableConnectionMenuController.h

#import <UIKit/UIKit.h> 
@class JackView; 

@interface CableConnectionMenuController : UIViewController 
{ 
JackView *outputJackView; 
} 

@property (nonatomic, weak) id <CableConnectionDelegate> delegate; 
@property (nonatomic, strong) JackView *outputJackView; 

- (void)setButtonTextWithOutputJack:(JackView *)outputJack withInputArray:(NSMutableArray *)inputArray; 
- (void)createAddConnectionButton; 
- (void)createDeleteConnectionButton; 
@end 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

//alloc output jack view 
self.outputJackView = [[JackView alloc] init]; 

//set size of popover view in cables view 
self.contentSizeForViewInPopover = CGSizeMake(200, 200); 

//change view background color 
self.view.backgroundColor = [UIColor whiteColor]; 
} 

//this method is called from the class that launches the UIPopoverViewController 
- (void)setButtonTextWithOutputJack:(JackView *)outputJack withInputArray:(NSMutableArray *)inputArray 
{ 
//set output jack which will be the same for all inputs 
self.outputJackView = outputJack; 

//draw add connection button 
[self createAddConnectionButton]; 

//draw delete connection button - not working 
//[self createDeleteConnectionButton]; 
} 

- (void)createAddConnectionButton 
{ 
CableDisconnectButton *addConnectionButton = [CableDisconnectButton buttonWithType:UIButtonTypeCustom]; 
addConnectionButton.frame = CGRectMake(0, 0, 190, 40); 
[addConnectionButton setBackgroundImage:[UIImage imageNamed:@"images/cable_connect_button.png"] forState:UIControlStateNormal]; 
[addConnectionButton setBackgroundImage:[UIImage imageNamed:@"images/cable_connect_button_over.png"] forState:UIControlStateHighlighted]; 

//add output jack 
addConnectionButton.outputJack = self.outputJackView; 

//add action to button 
[addConnectionButton addTarget:self action:@selector(addConnectionButtonTarget:) forControlEvents:UIControlEventTouchUpInside]; 

NSLog(@"output jack name before: %@", self.outputJackView.jackName); 

[self.view addSubview:addConnectionButton]; 

NSLog(@"output jack name after: %@", self.outputJackView.jackName); 
} 

끝에있는 두 개의 NSLog는 첫 번째 (이전)에 올바르게 이름을 반환하고 두 번째 (후)에 null을 반환합니다. jackName 속성은 NSString입니다. 하위보기가 추가 된 후에 속성이 null로 설정되는 것은 명백합니다. 그러나 그 이유가 무엇인지 파악할 수 없습니다.

- (void)editCableConnectionsWith:(JackView *)outputJack 
{ 
//launches the note menu popover 
self.cableConnectionMenuController = [[CableConnectionMenuController alloc] init]; 
self.cableConnectionMenuController.delegate = (id)self; 

//find appropriate connection to edit 
for (JackView *currentJack in jackArray) 
{ 
    if (currentJack == outputJack) 
    { 
     //create temp array of input jacks to send to cable connection controller 
     NSMutableArray *inputButtonTempArray = [self returnInputJackArrayWithOutputJack:currentJack]; 

     //set information for creating disconnect buttons in popover 
     [self.cableConnectionMenuController setButtonTextWithOutputJack:currentJack withInputArray:inputButtonTempArray]; 
    } 
} 

self.editConnectionsPopoverController = [[UIPopoverController alloc] initWithContentViewController:self.cableConnectionMenuController]; 

[self.editConnectionsPopoverController presentPopoverFromRect:pulseRing.frame inView:self permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 
} 
+0

추가 테스트가 끝나면이 UIViewController의 모든 속성은 하위보기를 추가 한 후에 null로 설정됩니다. 이것은 실제로 말이되지 않습니다. – anthony

답변

0

가 어떻게 jackName 속성이 선언 : 여기

는 중요한 경우에 UIPopoverViewController을 시작하는 클래스의 방법이다? 내 생각 엔 약한 참조입니다.

보기에 약한 참조가보기가 하위보기로 추가 된 후 다시 설정된 비슷한 문제가있었습니다. 제 생각에 약한 참조는 잠재적 인 유지주기가있을 때만 사용해야합니다 (예 : 계산기에 대한 참조가있는 배낭이 있고 계산기가 배낭을 가리킨다 - Big Nerd Ranch book 참조).

왜 여기에 문제가 있는지 잘 모르겠지만 비슷한 것을 발견하고 공유 할 것이라고 생각했습니다.

관련 문제