0

UIViewController のサブクラスである Objective-C クラスがあります。これは私のメイン ビューではありませんが、StoryBoard のセグエを介して ViewController からボタンが押されたときにアクセスされます。どちらもナビゲーションコントローラーに接続されているため、うまく切り替わります。しかし、私には問題があります。"DisplayView.m" ファイル (2 番目のビュー) で、いくつかの計算を行い、ラベルのテキストを設定したいと考えています。コードの計算部分に問題がないことはわかっています。これは、文字列を NSLog すると問題なく出力されるためです。ただし、ラベルは変更されません。これは、ストーリーボードの DisplayView シーンのセットアップです。

  • 「DisplayView」セットのカスタムクラス
  • IBOutlet にリンクされているラベル

それが役立つ場合は、これが DisplayView.m の私の imp ファイルです。追加の詳細が必要な場合はお知らせください。私が試したこと:

  • テキストを印刷する新しいメソッドの作成
  • 表示されるはずの出力をコンソールに記録します(完璧に機能します)
  • 別のラベルを試す
  • @property なしでラベル オブジェクトを使用しようとしています
  • 書式設定されていない文字列を設定しようとしています

これらのテストはどれもうまく機能せず、何が問題なのかわかりません。新しいビューはラベルなしでロードされます。ただし、StoryBoard でラベル テキストを変更すると表示されます。私のコードから値が表示されないだけです。

DisplayView.m

#import "DisplayView.h"

@interface DisplayView ()

@end

@implementation DisplayView
@synthesize months,days,seconds;

- (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.
}

-(void)calc:(int)m with:(int)d andWith:(int)y {

    NSString* bday = [NSString stringWithFormat:@"%i-%i-%i 00:00:00 +0000",m,d,y];
    NSDateFormatter *formatter = [NSDateFormatter new];
    [formatter setDateFormat:@"LL-dd-yyyy 00:00:00 +0000"];
    NSDate *date1 = [formatter dateFromString:bday];
    NSDate *date2 = [NSDate date];
    NSTimeInterval secondsBetween = [date2 timeIntervalSinceDate:date1];
    int numberOfDays = secondsBetween/86400;
    [days setText:@"asdadas"];
}


@end

DisplayView.h

#import <UIKit/UIKit.h>

@interface DisplayView : UIViewController {

    IBOutlet UILabel* months;
    IBOutlet UILabel* days;
    IBOutlet UILabel* seconds;


}


-(void)calc:(int)m with:(int)d andWith:(int)y;

@property UILabel* months;
@property UILabel* days;
@property UILabel* seconds;

@end
4

0 に答える 0