代码来自Stanford CS193p.我添加了一个NSLog来检查它.标签似乎没有初始化.任何的想法?
@interface AskerViewController() <UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UILabel *questionLabel;
@property (weak, nonatomic) NSString *question;
@end
@implementation AskerViewController
@synthesize questionLabel = _questionLabel;
@synthesize question = _question;
- (void)setQuestion:(NSString *)question
{
_question = question;
self.questionLabel.text = question;
NSLog(@"label is %@", self.questionLabel);
}
@end
Run Code Online (Sandbox Code Playgroud)
NSLog结果是:
2012-07-31 01:56:45.177 Kitchen Sink[23931:f803] label is (null)
Run Code Online (Sandbox Code Playgroud) 我一直在尝试设置一个脚本,在Debian 7.1系统上启动运行一段时间,但没有运气.我已经尝试过使用insserv和update-rc.d,但我的问题似乎与任何一个工具相同.这是我的脚本的LSB部分:
#!/bin/bash
### BEGIN INIT INFO
# Provides: start_guest
# Required-Start: $bootlogs $sudo $virtualbox-guest-utils $syslog
# Required-Stop: $bootlogs $sudo $virtualbox-guest-utils $syslog
# Should-Start:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start_guest
### END INIT INFO
Run Code Online (Sandbox Code Playgroud)
使用update-rc.d,以下是我尝试的各种命令,所有命令都具有相同的结果:
sudo update-rc.d start_guest defaults
sudo update-rc.d start_guest defaults 22
sudo update-rc.d start_guest start 22 2 3 4 5 . stop 78 2 3 4 5 .
Run Code Online (Sandbox Code Playgroud)
无论我跑哪一个,我都被告知(显示运行级别2只有2,3,4,5是相同的,0,1,6都是K01):
insserv: remove service /etc/init.d/../rc2.d/S21rc.local
insserv: enable service ../init.d/rc.local -> /etc/init.d/../rc2.d/S20rc.local …Run Code Online (Sandbox Code Playgroud) 我有一个我希望作为Singleton实现的类.
我希望通过以下方式创建/访问此类实例的唯一方法是:
+(MYClass*)sharedInstance
Run Code Online (Sandbox Code Playgroud)
方法.在方法实现中调用alloc和init(当然).
有没有办法阻止alloc和init的使用,或者让它们"空",如果尝试通过sharedInstance方法创建该类的实例(但直接通过alloc + init)?
我有一个用 Dart 编写的 http 服务器,我计划将其部署到 Linux 虚拟机。现在,我的测试/演示服务器在 Ubuntu 数字海洋液滴上。有没有人有比使用 linux init 服务脚本更好的 init 脚本或更好的方法?
编辑:
我现在的初始化脚本:
#! /bin/sh
### BEGIN INIT INFO
# Provides: dart
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts Dart
# Description: This will start the dart runtime and in turn, start
### END INIT INFO
# Author: David Marchbanks <ptdave20@gmail.com>
# Do NOT "set -e"
# PATH should only include /usr/* …Run Code Online (Sandbox Code Playgroud) 当 Java EE(Java Web 项目)启动(或收到第一个请求)时,有没有办法执行 Java 代码?我知道 servlet 有init()方法,但是整个应用程序有这样的方法吗?
我正在尝试按照以下说明将haskell-mode添加到emacs:
http://doc.gnu-darwin.org/haskell-mode/installation-guide.html
这涉及到我在~/.emacsinit文件中添加了一些代码.但是,我的问题是我无法找到我的emacs init文件.我尝试使用find命令来定位它,如下所示:
find . -name "*emacs*"
find . -name "~/.emacs"
Run Code Online (Sandbox Code Playgroud)
然而,这些似乎都不是很成功,因为我得到的结果太多,或者没有结果.
所以,鉴于我的情况,因为我无法找到我的~/.emacsinit文件,这是否意味着它不存在?在这种情况下,使用emacs编辑器自己创建一个是否聪明?如果是这样,在尝试创建之前我是否应该知道任何未完成的事情?
我是Swift的新手.
在目标C中,我从其类名推送自定义UIViewController create:
NSString *classString = "customViewController";
UIViewController *vc = [[NSClassFromString(classString) alloc] init];
[self pushViewController:vc animated:YES];
Run Code Online (Sandbox Code Playgroud)
我无法在swift中构建类,这不起作用:
let myClass = NSClassFromString("customViewController") as! UIViewController.Type
let vc = myClass.init()
self.presentViewController(vc, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
错误:致命错误:在解包可选值时意外发现nil
我收到错误:
类 AppDelegate 没有初始值设定项
并且似乎无法理解为什么。我正在关注本教程。我是初学者,因此非常感谢任何帮助!
我的代码:
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var centerContainer: MMDrawerController
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
_ = self.window!.rootViewController
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let centerViewController = mainStoryboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
let leftViewController = mainStoryboard.instantiateViewController(withIdentifier: "LeftSideViewController") as! LeftSideViewController
let leftSideNav = UINavigationController(rootViewController: leftViewController)
let centerNav = UINavigationController(rootViewController: centerViewController)
centerContainer = MMDrawerController(center: centerNav, …Run Code Online (Sandbox Code Playgroud) 代码:
class HeaderView: UIView {
@IBOutlet weak var titleLabel: UILabel!
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
finishInit()
}
func finishInit() {
titleLabel.backgroundColor = UIColor.white
}
func setView(withTitle title: String?) {
titleLabel.backgroundColor = UIColor.white
titleLabel.text = title
}
Run Code Online (Sandbox Code Playgroud)
碰撞:
在finishInit() 方法上,同时设置标签背景颜色
fatal error: unexpectedly found nil while unwrapping an Optional value
Run Code Online (Sandbox Code Playgroud)
但同样,在 setView() 方法上,没有崩溃。
我使用自定义 initrd 在用户模式下编译了 Linux 内核 5.6,使用以下方法创建:
mkdir initrd
cd initrd
mkdir bin dev etc home mnt proc sys usr
mknod dev/console c 5 1
Run Code Online (Sandbox Code Playgroud)
带initrd/init.c初始化文件
#include <stdio.h>
#include <stdlib.h>
#include <sys/mount.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
printf("init\n");
mount("none", "/proc", "proc", MS_MGC_VAL, "");
mount("none", "/sys", "sysfs", MS_MGC_VAL, "");
mount("none", "/dev", "devtmpfs", MS_MGC_VAL, "");
if (access("/dev/ubda", F_OK) != -1) {
printf("/dev/ubda exists\n");
} else {
printf("/dev/ubda not exists\n");
}
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
该程序检查通过ubd0=...选项传递的磁盘。
与gcc …
init ×10
ios ×4
swift ×3
alloc ×1
appdelegate ×1
c ×1
classname ×1
cs193p ×1
dart ×1
debian ×1
emacs ×1
haskell-mode ×1
jakarta-ee ×1
java ×1
linux ×1
linux-kernel ×1
objective-c ×1
setter ×1
singleton ×1
ubuntu ×1
uikit ×1