我正在尝试在 iphone 中的两个视图之间传递控件。我已经尝试过了,当您从第一个视图控制器传递到第二个时它工作正常,但是当我单击第二个时,它会空白。为什么呢?任何帮助表示赞赏.. 谢谢...
视图控制器.h
#import <UIKit/UIKit.h>
#import "ViewController2nd.h"
@interface ViewController : UIViewController <SecondViewControllerDelegate>
{
IBOutlet UILabel *lbl;
}
-(IBAction)passdata:(id)sender;
@end
视图控制器.m
#import "ViewController.h"
#import "ViewController2nd.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void) changeLabel:(NSString*)str{
lbl.text = @"Hello";
}
-(IBAction)passdata:(id)sender{
ViewController2nd *second = [[ViewController2nd alloc] initWithNibName:nil bundle:nil];
[self presentViewController:second animated:YES completion:^{ }];
}
@end
ViewController2nd.h
#import <UIKit/UIKit.h>
@protocol SecondViewControllerDelegate <NSObject>
@optional
-(void) changeLabel:(NSString*)str;
@end
@interface ViewController2nd : UIViewController{
IBOutlet UIButton *bttn;
}
-(IBAction)bttnclicked;
-(IBAction)back:(id)sender;
@end
ViewController2nd.m
#import "ViewController2nd.h"
#import "ViewController.h"
@interface ViewController2nd ()
@end
@implementation ViewController2nd
- (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 from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)bttnclicked{
}
-(IBAction)back:(id)sender{
ViewController *first = [[ViewController alloc] initWithNibName:nil bundle:nil];
[self presentmodalViewController:first animated:YES completion:^{ }];
}
@end
我错过了什么吗?