0

UITabBarView の一部である UITextView でテキストを表示したいので、次のクラスで行います。

.h - ファイル:

#import <UIKit/UIKit.h>

@interface DescriptionViewController : UIViewController{

IBOutlet UITextView *descriptionText;

}
@end

.m - ファイル:

#import "DescriptionViewController.h"
#import "Globals.h"

@interface DescriptionViewController ()


@end

@implementation DescriptionViewController



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

- (void)viewDidLoad
{
    [super viewDidLoad];

}

-(void) viewWillAppear:(BOOL)animated{

    Globals* myGlobals = [Globals sharedGlobals];

    descriptionText.text = [myGlobals.currentLine objectAtIndex:5];

}


@end

When the TextView is displayed the first time it is empty, when i switch to another tab and switch back to the "TextView - Tab" it is displayed properly. But I obviously want it to be displayed correctly the first time..

I already tried to move the relevant code to the -viewDidLoad function, but nothing changed. Also, I tried the -setNeedsDisplay function without success (maybe I used it wrong? - [descriptionText setNeedsDisplay].

I appreciate any help and further code will be posted on request.

4

2 に答える 2

1

クラスの ViewWillAppear メソッドにブレークポイントを設定してから、NSLog("%@", [myGlobals.currentLine objectAtIndex:5]); から取得しているものを最初に確認してください。

[super viewWillAppear:animated] がありません。

于 2012-09-14T09:01:43.967 に答える
0

これを試して、

- (void)viewDidLoad
{
    [super viewDidLoad];
    Globals* myGlobals = [Globals sharedGlobals];

    descriptionText.text = [myGlobals.currentLine objectAtIndex:5];
}

-(void) viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    Globals* myGlobals = [Globals sharedGlobals];

    descriptionText.text = [myGlobals.currentLine objectAtIndex:5];

}
于 2012-09-14T08:59:11.110 に答える