使用segue和story board从一个控制器移动到另一个控制器

时间:2013-08-27 13:27:14

标签: iphone ios objective-c

我已经完成了苹果开发者工具资源中的第一个教程,在那里你做了一个输入,标签和按钮我想要的是这样做当你按下按钮它会带你到一个新的场景所以我已经设置了segue,我把它作为“testPush”现在,当我按下按钮时,我怎么实际让它移动我得到一个错误说

**Thread 1: signal SIGABRT**

它回复的代码就是这个

return UIApplicationMain(argc, argv, nil, NSStringFromClass([HelloWorldAppDelegate class]));

任何人都有任何想法我知道你需要为segue添加代码才能工作但是我所看到的一切都没有意义,或者它是一个代码块,几乎没有任何指令意味着你如何得到它工作等。感谢您的帮助

你可能需要的其他东西我不确定 场景一被称为:HelloWorldViewController 场景二被称为:HelloWorldViewController2

修改

继承我的脚本代码包含你需要的感谢。 HelloWorldViewController.m

    #import "HelloWorldViewController.h"
    @interface HelloWorldViewController ()
    @property (weak, nonatomic) IBOutlet UITextField *textField;
    @property (weak, nonatomic) IBOutlet UILabel *label;
    - (IBAction)changeGreeting:(id)sender;
    @end
@implementation HelloWorldViewController
- (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.
}

- (IBAction)changeGreeting:(id)sender {

    self.userName = self.textField.text;

    NSString *nameString = self.userName;
    if ([nameString length] == 0) {
        nameString = @"World";
    }
    NSString *greeting = [[NSString alloc] initWithFormat:@"Hello, %@!", nameString];
    self.label.text = greeting;
}

    - (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
        if (theTextField == self.textField) {
            [theTextField resignFirstResponder];
        }
        return YES;
    }

@end

HelloWorldViewController.h

#import <UIKit/UIKit.h>

@interface HelloWorldViewController : UIViewController <UITextFieldDelegate>

@property (copy,nonatomic) NSString *userName;

@end

和main.m

#import <UIKit/UIKit.h>

#import "HelloWorldAppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([HelloWorldAppDelegate class]));
    }
}

1 个答案:

答案 0 :(得分:1)

尝试在performseguewithidentifier中添加IBAction,如下所示:

- (IBAction)changeGreeting:(id)sender {

self.userName = self.textField.text;

NSString *nameString = self.userName;
if ([nameString length] == 0) {
    nameString = @"World";
}
NSString *greeting = [[NSString alloc] initWithFormat:@"Hello, %@!", nameString];
self.label.text = greeting;

[self performSegueWithIdentifier:@"segueId" sender:nil];
}

应该为你推新。