我是初学者 iPhone 开发人员。
我有2节课。TestViewController
(这与情节提要中的视图相关联)和ViewController
.
我试图调用一个方法([tc refresh:val];
)作为类TestViewController
的val
参数ViewController
。我可以从val
到达的日志中看到TestViewController
,但由于某种原因,标签没有更新,我也没有得到我在视图中设置的标签的当前文本。它赋予null
价值。请查看我得到的代码和日志,并建议我如何通过调用 from VC
to的方法来更新标签TVC
。
测试视图控制器.h
#import <UIKit/UIKit.h>
#import "ViewController.h"
@interface TestViewController : UIViewController
@property (retain, nonatomic) IBOutlet UILabel *lblDisp;
- (IBAction)chngText:(id)sender;
- (void)refresh:(NSString *)val;
@end
测试视图控制器.m
#import "TestViewController.h"
#import "ViewController.h"
@implementation TestViewController
@synthesize lblDisp;
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"TEST VC LOADED");
NSLog(@"TEXT CUrret VALUE SUPERVIEW %@",lblDisp.text);
}
- (IBAction)chngText:(id)sender {
ViewController *dd=[[ViewController alloc]init];
[dd display];
}
-(void)refresh:(NSString *)val{
NSLog(@"Value of Val = %@",val);
NSLog(@"TEXT CUrret VALUE %@",lblDisp.text);
lblDisp.text=val;
}
@end
视图控制器.h
#import <UIKit/UIKit.h>
#import "TestViewController.h"
@interface ViewController : UIViewController
-(void)display;
@end
视图控制器.m
#import "ViewController.h"
#import "TestViewController.h"
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"VC LOADED");
}
-(void)display{
NSLog(@"Reached VC");
NSString *val=@"1";
TestViewController *tc=[[TestViewController alloc]init];
[tc refresh:val];
}
@end
日志
2013-07-24 03:13:36.413 Simple test[38477:11303] TEST VC LOADED
2013-07-24 03:13:36.415 Simple test[38477:11303] TEXT CUrret VALUE SUPERVIEW sdfgdfgd
2013-07-24 03:13:37.909 Simple test[38477:11303] Reached VC
2013-07-24 03:13:37.910 Simple test[38477:11303] Value of Val = 1
2013-07-24 03:13:37.911 Simple test[38477:11303] TEXT CUrret VALUE (null)