#import "OtherController.h"
#import "ViewController.h"
ViewController *viewController;
@interface OtherController ()
@end
@implementation OtherController
- (void)viewDidLoad
{
[super viewDidLoad];
viewController = [[ViewController alloc] initWithNibName:@"viewController" bundle:nil];
}
- (IBAction)levelNormal{
viewController.level = 1;
[self.navigationController pushViewController:viewController animated:YES];
}
我已经尝试了我在 stackoverflow 上阅读的各种提示,尽管它们似乎都没有正确工作。我试图在单击按钮时打开 View ,当 View 打开时,根据按下的按钮, View 应该有不同的“级别”编号。就我而言,我没有 NavigationController。我已经阅读了有关将代码粘贴到 AppDelegate 类中的不同帖子,尽管这对我来说也不起作用。当我调试按钮的按下时,我看到该值已更改,但当它尝试更改 View 时没有其他任何 react 。
这是 ViewController 头文件:
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIButton *resumeButton;
@property (weak, nonatomic) IBOutlet UIImageView *opacityScreen;
@property (weak, nonatomic) IBOutlet UILabel *scoreField;
@property (weak, nonatomic) IBOutlet UIButton *pauseButton;
@property (weak, nonatomic) IBOutlet UIButton *mainMenuButton;
@property (weak, nonatomic) NSTimer * nst;
@property(nonatomic) int level;
@end
最佳答案
在 AppDelegate 的 didFinishLaunchingWithOptions 中创建 UINavigationController 对象,并将 UIViewcontroller 对象分配为如下所示的 rootViewController 并将 navObj 传递给窗口 Root View 。
viewController = [[ViewController_iPhone alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
UINavigationController *navObj = [[UINavigationController alloc] initWithRootViewController:viewController];
[self.window setRootViewController:navObj];
关于ios - Objective-C 赋予下一个 View 值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23102825/