在我的应用程序中,当用户按下按钮时,我想在不同的视图上生成有关该主题的信息。例如,当用户按下 cat 按钮时,我想要一个新视图来显示标题和描述。但是,当他们按下 dog 时,它会转到相同的视图,但会更改信息。
第一视图控制器.h
#import "secondview.h"
@interface ViewController :UIViewController
{
secondview *secondviewData;
IBOutlet UITextField *textfield;
}
@property (nonatomic, retain)secondview*secondviewData;
-(IBAction)passdata:(id)sender;
@end
第一视图控制器.m
#import "ViewController.h"
#import "secondview.h"
@implementation ViewController
@synthesize secondviewData;
-(IBAction)passdata:(id)sender
{
secondview *second = [[secondview alloc] initWithNibName:nil bundle:nil];
self.secondviewData = second;
secondviewData.passedValue = @"dog Info";
[self presentModalViewController:second animated:YES];
}
@end
secondViewController.h
@interface secondview :UIViewController
{
IBOutlet UILabel *label;
NSString *passedValue;
}
@property (nonatomic, retain)NSString *passedValue;
-(IBAction)back:(id)sender;
@end
第二视图控制器.m
#import "ViewController.h"
@implementation secondview
@synthesize passedValue;
-(IBAction)back:(id)sender
{
ViewController *second = [[ViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
}
- (void)viewDidLoad
{
label.text = passedValue;
[super viewDidLoad];
}
@end
当我执行这段代码时,它会出现SIGABRT