0

私はxcodeを使った開発に不慣れで、アップルのチュートリアル「Second'siosapptutorial」に従っています。シーンに「SightingViewControllerの追加」ボタンを追加しましたが、このビューを鳥の名前のリストがある別のビュー(BirdsViewController)に切り替えたいと思います。ストーリーボードでは、ボタンとBirdsViewControllerの間にセグエを作成し、ボタンを接続して内部を修正しましたが、アプリを実行してもボタンが表示されません。誰か助けてもらえますか?ありがとうございます。これが私のコードです(私は他のメソッドを実装していません):

AddSightingViewController.h

@class BirdSighting;

@interface AddSightingViewController : UITableViewController  

@property (weak, nonatomic) IBOutlet UITextField *birdNameInput;

@property (weak, nonatomic) IBOutlet UITextField *locationInput;

@property (strong, nonatomic) BirdSighting *birdSighting;

@property (strong, nonatomic)  UIButton *showBirds;

-(IBAction)displayBirds:(id)sender;

AddSightingViewController.m

#import "AddSightingViewController.h"

#import "BirdSighting.h"

#import "BirdsViewController.h"

#import <UIKit/UIKit.h>


@class BirdSighting;

@interface AddSightingViewController ()

@end

@implementation AddSightingViewController

@synthesize showBirds;

-(BOOL)textFieldShouldReturn:(UITextField *)textField {

    if((textField == self.birdNameInput) || (textField == self.locationInput)) {

        [textField resignFirstResponder];   
    }
      return YES;    
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if([[segue identifier] isEqualToString:@"ReurnInput"]) {

        if ([self.birdNameInput.text length] || [self.locationInput.text length])

        {
            BirdSighting *sighting;

            NSDate *today = [NSDate date];

            sighting = [[BirdSighting alloc] initWithName:self.birdNameInput.text
                                             location:self.locationInput.text date:today];

            self.birdSighting = sighting;
        }    
    }   
}

 BirdsViewController *viewController;

-(IBAction)showBirds:(id)sender {

    viewController =
    [[BirdsViewController alloc]
     initWithNibName:@"BirdsViewController" bundle:nil];
    [[self navigationController] pushViewController:viewController animated:YES];   
}
4

1 に答える 1

0

ビューコントローラーのビューへのサブビューとしてのボタンの割り当てと追加は見られません。

アプリでは他のテキストフィールドと同じように、ボタンも IBOutlet だと思います。ボタンを IBOutlet として宣言し、インターフェイス ビルダー ファイルでアウトレットをボタンに接続します。

@property (弱い、非アトミック) IBOutlet UIButton *showBirds;

または、ボタンを割り当てて、ビューコントローラーのビューにサブビューとして追加します。

于 2013-01-28T20:53:26.587 に答える