0

2 つのビュー コントローラーがあります。これが私のコードです:

SelectFavorites.h

@class SelectFavorites;
@protocol SelectFavoritesDelegate <NSObject>
- (void)addItemViewController:(SelectFavorites *)controller didFinishEnteringItem:    (NSString *)item;
@end


#import <UIKit/UIKit.h>
#import "GameFavorites.h"

@interface SelectFavorites : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource>

@property (nonatomic, weak) id <SelectFavoritesDelegate> delegate;
- (IBAction)button1:(UIButton *)sender;
@end

SelectFavorites.m

#import "SelectFavorites.h"
#import "GameFavorites.h"



@interface SelectFavorites ()


@end

@implementation SelectFavorites

- (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)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)button1:(UIButton *)sender {

NSString *itemToPassBack = @"Pass this value back to Gamefavorites";
[self.delegate addItemViewController:self didFinishEnteringItem:itemToPassBack];


}

@end

GameFavorites.h

#import <UIKit/UIKit.h>
#import "SelectFavorites.h"

@interface GameFavorites : UITableViewController <SelectFavoritesDelegate>
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@end

GameFavorites.m

#import "GameFavorites.h"

@interface GameFavorites ()

@end

@implementation GameFavorites


- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {


    SelectFavorites *selectFavorites = [[SelectFavorites alloc]   initWithNibName:@"SelectFavorites" bundle:nil];
    selectFavorites.delegate = self;

[self.navigationController pushViewController:selectFavorites animated:YES];

    // Custom initialization
}
return self;
}



//view did load is called when your view is actually presented onscreen
- (void)viewDidLoad
{
[super viewDidLoad];

}


- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}



- (void)addItemViewController:(SelectFavorites *)controller didFinishEnteringItem:(NSString *)item
{

NSLog(@"This was returned from ViewControllerB %@",item);


}

ボタンを押したときにコンソールに文字列が表示されるべきではありませんか? 正常に動作するエラーはありませんが、コンソールには何も表示されません。

いくつかの考え:

  • プッシュするビューコントローラーはテーブルビューコントローラーですが、それは問題ではないと思います。
  • 私のinitメソッドまたはviewDidLoadメソッドを編集する必要があるかもしれませんが、どこにあるのかわかりません。
4

0 に答える 0