Objective c 返回MainViewController时发出信号
在我的应用程序中,当用户按下一个按钮时,我希望在不同的视图中生成有关该主题的信息。例如,当用户按下cat按钮时,我希望出现一个显示标题和描述的新视图。然而,当他们按下dog时,它会进入相同的视图,但它会更改信息 firstViewController.hObjective c 返回MainViewController时发出信号,objective-c,cocoa-touch,sigabrt,Objective C,Cocoa Touch,Sigabrt,在我的应用程序中,当用户按下一个按钮时,我希望在不同的视图中生成有关该主题的信息。例如,当用户按下cat按钮时,我希望出现一个显示标题和描述的新视图。然而,当他们按下dog时,它会进入相同的视图,但它会更改信息 firstViewController.h #import "secondview.h" @interface ViewController :UIViewController { secondview *secondviewData; IBOutlet UIText
#import "secondview.h"
@interface ViewController :UIViewController
{
secondview *secondviewData;
IBOutlet UITextField *textfield;
}
@property (nonatomic, retain)secondview*secondviewData;
-(IBAction)passdata:(id)sender;
@end
@interface secondview :UIViewController
{
IBOutlet UILabel *label;
NSString *passedValue;
}
@property (nonatomic, retain)NSString *passedValue;
-(IBAction)back:(id)sender;
@end
firstViewController.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
#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
secondViewController.h
#import "secondview.h"
@interface ViewController :UIViewController
{
secondview *secondviewData;
IBOutlet UITextField *textfield;
}
@property (nonatomic, retain)secondview*secondviewData;
-(IBAction)passdata:(id)sender;
@end
@interface secondview :UIViewController
{
IBOutlet UILabel *label;
NSString *passedValue;
}
@property (nonatomic, retain)NSString *passedValue;
-(IBAction)back:(id)sender;
@end
SecondViewController.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
#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
如果您的下一个视图与当前视图分离,您可以使用:
---------------------------还有另一种方法:--------------------------- 可以使用全局变量传递参数 创建一个类 h m
好吧,看看你的控制台(Cmd-Shift-R)。这很好,但我不使用故事板。那么我该怎么做呢?然后,你可以使用第二种方法:全局变量。