두 개의 버튼 (버튼 추가 및 삭제)을 그려야하는 UIPopoverViewController를 시작합니다. UIPopover에 대한 ContentViewController는 UIPopoverViewController가 시작되기 직전에 설정된 outputJackView
이라는 속성을 가지고 있습니다. 이 속성은 버튼을 올바르게 그리는 데 필요합니다. 문제는 첫 번째 버튼이 하위보기로 추가 된 직후인데 outputJackView
은 null로 설정됩니다. 여기 하위 뷰를 추가 한 후에 속성이 null입니다.
#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];
}
추가 테스트가 끝나면이 UIViewController의 모든 속성은 하위보기를 추가 한 후에 null로 설정됩니다. 이것은 실제로 말이되지 않습니다. – anthony