1

私はApressのBeginningiOS5開発のMultiviewApplicationsの章で作業していて、ビューの1つのボタンからファイル所有者への接続を確立する際に問題が発生しました。プログラムの一般的な前提は、ルートコントローラーBIDSwitchViewControllerを使用して、2つのコンテンツビューBIDBlueViewControllerとBIDYellowViewControllerを切り替えることです。各コンテンツビューには、TouchUpInsideイベントをファイルの所有者に接続する単一のボタンがあります。BIDBlueViewControllerで接続を確立するのに問題はありませんでしたが、BIDYellowViewControllerでこの接続を確立しようとすると、TouchUpInsideイベントとファイルの所有者アイコンを接続できません。

本の状態の指示

ガイドラインを使用して、ラウンドレクボタンをライブラリからビューにドラッグし、ボタンを垂直方向と水平方向の両方でビューの中央に配置します。ボタンをダブルクリックし、タイトルをPressMeに変更します。次に、ボタンを選択したまま、接続インスペクターに切り替えて、Touch Up Insideイベントからファイルの所有者アイコンにドラッグし、blueButtonPressedアクションメソッドに接続します

私は問題なくこれを行うことができますが、イエロービューのこの手順を完了しようとすると

ガイドラインを使用して、ラウンドレクボタンをライブラリからビューにドラッグし、ボタンを垂直方向と水平方向の両方でビューの中央に配置します。ボタンをダブルクリックし、タイトルをPressMeに変更します。次に、ボタンを選択したまま、接続インスペクターに切り替えて、Touch Up Insideイベントからファイルの所有者アイコンにドラッグし、yellowButtonPressedアクションメソッドに接続します。

Touch Up Insideイベントからファイル所有者アイコンにドラッグすると、ファイル所有者アイコンが接続できなくなります。ファイル所有者が強調表示されず、接続できません。

これが私のコードです

ルートコントローラーインターフェイス

//
//  BIDSwitchViewController.h
//  ViewSwitcher
//
//  

#import <UIKit/UIKit.h>

@class BIDYellowViewController;
@class BIDBlueViewController;

@interface BIDSwitchViewController : UIViewController

@property (strong, nonatomic) BIDYellowViewController *yellowViewController;
@property (strong, nonatomic) BIDBlueViewController *blueViewController;

- (IBAction)switchViews:(id)sender;

@end

ルートコントローラーの実装

//
//  BIDSwitchViewController.m
//  ViewSwitcher
//

#import "BIDSwitchViewController.h"
#import "BIDYellowViewController.h"
#import "BIDBlueViewController.h"

@implementation BIDSwitchViewController
@synthesize yellowViewController;
@synthesize blueViewController;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    self.blueViewController = [[BIDBlueViewController alloc]
                               initWithNibName:@"BlueView" bundle:nil];
    [self.view insertSubview:self.blueViewController.view atIndex:0];
    [super viewDidLoad];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)switchViews:(id)sender{
    if (self.yellowViewController.view.superview == nil){
        if (self.yellowViewController == nil) {
        self.yellowViewController = 
    [[BIDYellowViewController alloc] initWithNibName: @"YellowView" 
                                              bundle:nil];
    }
    [blueViewController.view removeFromSuperview];
    [self.view insertSubview:self.yellowViewController.view atIndex:0];
} else {
    if (self.blueViewController == nil){
        self.blueViewController = [[BIDBlueViewController alloc] initWithNibName:@"BlueView" 
                                                                          bundle:nil];
    }
    [yellowViewController.view removeFromSuperview];
    [self.view insertSubview:self.blueViewController.view atIndex: 0];
    }
}



- (void) didReceiveMemoryWarning {
    // Release the view if it doesn't have a super view
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc, that aren't in use
    if (self.blueViewController.view.superview == nil){
        self.blueViewController = nil;
    } else {
        self.yellowViewController = nil;
    }
}

@end

青いコンテンツビューコントローラインターフェイス

//
//  BIDSwitchViewController.h
//  ViewSwitcher
//

#import <UIKit/UIKit.h>

@class BIDYellowViewController;
@class BIDBlueViewController;

@interface BIDSwitchViewController : UIViewController

@property (strong, nonatomic) BIDYellowViewController *yellowViewController;
@property (strong, nonatomic) BIDBlueViewController *blueViewController;

- (IBAction)switchViews:(id)sender;

@end

青いコンテンツビューコントローラーの実装

//
//  BIDBlueViewController.m
//  ViewSwitcher
//
//  

#import "BIDBlueViewController.h"

@interface BIDBlueViewController ()

@end

@implementation BIDBlueViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

黄色のコンテンツビューコントローラインターフェイス

//
//  BIDYellowViewController.h
//  ViewSwitcher
//

#import <UIKit/UIKit.h>

@interface BIDYellowViewController : UIViewController

- (IBAction)yellowButtonPressed;

@end

黄色のコンテンツビューコントローラーの実装

//
//  BIDYellowViewController.m
//  ViewSwitcher
//
//  

#import "BIDYellowViewController.h"

@interface BIDYellowViewController ()

@end

@implementation BIDYellowViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
4

0 に答える 0