- (IBAction)submitButtonClicked:(id)sender{
NSLog(@"here");
SuccessOrFailViewController *sfvc = [[SuccessOrFailViewController alloc] init];
[self presentViewController:sfvc animated:NO completion:NULL];
}
Run Code Online (Sandbox Code Playgroud)
我想在用户点击应用中的提交按钮时打开新页面.但是,这会打开完全黑屏,上面没有任何内容.如何让它打开viewController呢?
我试图将一个double分成整数和小数部分
例如,数字24.4应分为24和4.
int integer = (int)number;
double decimal = number-(int)number;
System.out.println(decimal);
Run Code Online (Sandbox Code Playgroud)
使用此方法为我提供以下值:
integer = 24
decimal = 0.3999999999999986
Run Code Online (Sandbox Code Playgroud)
我需要十进制的值为4.
如何解决这个问题?
我想尝试使用java.util.zip中的Deflate和Inflate类进行zlib压缩.
我能够使用Deflate压缩代码,但在解压缩时,我遇到了这个错误 -
Exception in thread "main" java.util.zip.DataFormatException: unknown compression method
at java.util.zip.Inflater.inflateBytes(Native Method)
at java.util.zip.Inflater.inflate(Inflater.java:238)
at java.util.zip.Inflater.inflate(Inflater.java:256)
at zlibCompression.main(zlibCompression.java:53)
Run Code Online (Sandbox Code Playgroud)
这是我目前的代码 -
import java.util.zip.*;
import java.io.*;
public class zlibCompression {
/**
* @param args
*/
public static void main(String[] args) throws IOException, DataFormatException {
// TODO Auto-generated method stub
String fname = "book1";
FileReader infile = new FileReader(fname);
BufferedReader in = new BufferedReader(infile);
FileOutputStream out = new FileOutputStream("book1out.dfl");
//BufferedInputStream in = new BufferedInputStream(new FileInputStream(filename));
Deflater compress = new Deflater();
Inflater …Run Code Online (Sandbox Code Playgroud) 我试图将两个参数传递给C中的一个线程.我创建了一个数组(大小为2),并试图将该数组传递给线程.这是将多个参数传递给线程的正确方法吗?
// parameters of input. These are two random numbers
int track_no = rand()%15; // getting the track number for the thread
int number = rand()%20 + 1; // this represents the work that needs to be done
int *parameters[2];
parameters[0]=track_no;
parameters[1]=number;
// the thread is created here
pthread_t server_thread;
int server_thread_status;
//somehow pass two parameters into the thread
server_thread_status = pthread_create(&server_thread, NULL, disk_access, parameters);
Run Code Online (Sandbox Code Playgroud) 我试图在我的应用程序的UILabel视图中垂直对齐文本.问题是我希望文本垂直对齐顶部,标签的大小为280 x 150.我只能实现这两件事之一.如果我删除该行
[myLabel sizeToFit];
Run Code Online (Sandbox Code Playgroud)
然后文本的对齐没问题但是大小搞砸了.但是如果我添加上面的行,那么对齐就搞砸了但是大小没问题.我该如何解决这个问题.
我已添加以下代码 -
CGRect labelFrame = CGRectMake(22, 50, 280, 150);
UILabel *myLabel = [[UILabel alloc] initWithFrame:labelFrame];
[myLabel setText:finalRecipe];
[myLabel setBackgroundColor: [UIColor lightGrayColor]];
[myLabel setNumberOfLines:0];
[myLabel sizeToFit];
[self.view addSubview:myLabel];
Run Code Online (Sandbox Code Playgroud) 我有一个UIButton,我试图将它连接到两个segues.使用哪种segue取决于许多条件.
例如,当按下UIButton(标题为"next")时,
if(条件1)然后转到屏幕A.否则转到屏幕B.
我相信我的代码是正确的(无论如何我已经包含它),但问题是在故事板视图中,我可以使用segue将一个按钮连接到一个视图控制器.我该如何解决 ?
这是我正在使用的代码 -
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier]isEqualToString:@"nextButtonID"]){
creditCardViewController *cvc = [segue destinationViewController];
}
else if([[segue identifier]isEqualToString:@"next2ButtonID"]){
depositInfoViewController *divc = [segue destinationViewController];
}
}
-(IBAction)nextClicked{
if([accountType isEqualToString:@"patron"]){
[self performSegueWithIdentifier:@"nextButtonID" sender:self];
}
else{
[self performSegueWithIdentifier:@"next2ButtonID" sender:self];
}
}
Run Code Online (Sandbox Code Playgroud) 我需要将以下参数设置为Eclipse中的默认VM参数
-javaagent /Developer/aspectj-1.6/aspectjweaver.jar
Run Code Online (Sandbox Code Playgroud)
当我添加该行并运行我的代码时,它会给我错误:
Unrecognized option: -javaagent
Could not create the Java virtual machine.
Run Code Online (Sandbox Code Playgroud)
我该如何解决 ?
我正在尝试在我的mac上安装PHP的mcrypt扩展.
我用homebrew命令安装它
brew install php53-mcrypt
Run Code Online (Sandbox Code Playgroud)
这给了我一条消息说它已经安装: php53-mcrypt-5.3.26 already installed
但是,当我运行命令时php -m,我没有在列表中看到mcrypt(我已经重新启动了终端).
编辑1:添加php.ini.default的mcrypt部分
在php.ini.default文件中,这是我关于mcrypt的部分
[mcrypt]
; For more information about mcrypt settings see http://php.net/mcrypt-module-open
; Directory where to load mcrypt algorithms
; Default: Compiled in into libmcrypt (usually /usr/local/lib/libmcrypt)
;mcrypt.algorithms_dir=
; Directory where to load mcrypt modes
; Default: Compiled in into libmcrypt (usually /usr/local/lib/libmcrypt)
;mcrypt.modes_dir=
Run Code Online (Sandbox Code Playgroud) 我使用以下行在我的Swift应用程序中打开外部URL:
UIApplication.sharedApplication().openURL(url)
Run Code Online (Sandbox Code Playgroud)
这很好用,直到我通过CocoaPods将Realm添加到我的项目中.那时,它开始给我下面的两个编译错误:
'sharedApplication()'不可用:在适当的情况下使用基于视图控制器的解决方案.
'openURL'不可用
这些错误表明API不适用于Application Extensions,但我的代码是在正常的应用程序中,而不是扩展.为什么添加Realm会导致编译器认为它在App扩展中?
我正在尝试在interviewstreet.com上解决字符串相似性问题.我的代码适用于7/10个案例(超过了其他3个案例的时间限制).
这是我的代码 -
public class Solution {
public static void main(String[] args) {
Scanner user_input = new Scanner(System.in);
String v1 = user_input.next();
int number_cases = Integer.parseInt(v1);
String[] cases = new String[number_cases];
for(int i=0;i<number_cases;i++)
cases[i] = user_input.next();
for(int k=0;k<number_cases;k++){
int similarity = solve(cases[k]);
System.out.println(similarity);
}
}
static int solve(String sample){
int len=sample.length();
int sim=0;
for(int i=0;i<len;i++){
for(int j=i;j<len;j++){
if(sample.charAt(j-i)==sample.charAt(j))
sim++;
else
break;
}
}
return sim;
}
}
Run Code Online (Sandbox Code Playgroud)
这是问题 -
对于两个字符串A和B,我们将字符串的相似性定义为两个字符串共有的最长前缀的长度.例如,字符串"abc"和"abd"的相似性是2,而字符串"aaa"和"aaab"的相似性是3.
计算字符串S与每个后缀的相似之和.
输入:
第一行包含测试用例T的数量.下一个T行中的每一行都包含一个字符串.
输出:
输出T行包含相应测试用例的答案.
约束:
1 <= T <= …