我正在尝试编写一个应用程序从url下载pdf,将它们存储在sd上,然后由adobe pdf reader或其他能够打开pdf的应用程序打开.
直到现在,我已经"成功下载并将其存储在Sd卡上"(但每当我尝试使用pdf阅读器打开pdf时,阅读器崩溃并发出意外错误),例如,http://maven.apache.组织/ Maven的1.x中/ maven.pdf
这是我的下载程序的代码:
//........code set ui stuff
//........code set ui stuff
new DownloadFile().execute(fileUrl, fileName);
private class DownloadFile extends AsyncTask<String, Void, Void>{
@Override
protected Void doInBackground(String... strings) {
String fileUrl = strings[0]; // -> http://maven.apache.org/maven-1.x/maven.pdf
String fileName = strings[1]; // -> maven.pdf
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File folder = new File(extStorageDirectory, "testthreepdf");
folder.mkdir();
File pdfFile = new File(folder, fileName);
try{
pdfFile.createNewFile();
}catch (IOException e){
e.printStackTrace();
}
FileDownloader.downloadFile(fileUrl, pdfFile);
return null;
}
}
public class FileDownloader { …
Run Code Online (Sandbox Code Playgroud) NSString *s = @"0800 444 333";
Run Code Online (Sandbox Code Playgroud)
如您所见,此字符串中间有2个空格.我的问题是,如何摆脱它们,以便字符串可以变为:
s = @"0800444333"
Run Code Online (Sandbox Code Playgroud) 我有"food_db.sql"文件存储在/ res/raw文件夹中,它有大量的"插入".
我的问题是如何执行该文件并将数据导入我的Android应用程序中的sqlite数据库?
这是我的数据库代码.任何建议?
private static class DbHelper extends SQLiteOpenHelper{
public DbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_NAME + " TEXT NOT NULL, " +
KEY_HOTNESS + " TEXT NOT NULL);");
// how do i exec the sql file and get the data into this DB table?
}
@Override …
Run Code Online (Sandbox Code Playgroud) 这是我处理服务器响应的代码.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"connectionDidFinishLoading : %@", [[NSString alloc] initWithData:self.data encoding:NSUTF8StringEncoding]);
}
Run Code Online (Sandbox Code Playgroud)
这是消息服务器对我的响应,NSLog JSON显示在控制台中.
connectionDidFinishLoading : {"ErrorCode":"CssParameterException","ErrorMessage":"An error has occurred, please try again later.","Success":false}
Run Code Online (Sandbox Code Playgroud)
我的问题是:如何反序列化JSON并将其存储到局部变量中NSDictionary *jsonData
?
有什么建议?请给我一些代码示例,谢谢!
我在我的NSUserDefault中设置了关键TCshow的bool值,我想运行nslog测试是否保存了密钥,并且我试图打印输出bool值.这是我的代码,但它没有用,有什么建议吗?
- (IBAction)acceptAction:(id)sender {
//key store to nsuserdefault
self.storedKey = [[NSUserDefaults alloc] init];
[self.storedKey setBool:YES forKey:@"TCshow"];
//trying to print out yes or not, but not working...
NSLog(@"%@", [self.storedKey boolForKey:@"TCshow"]);
}
Run Code Online (Sandbox Code Playgroud) 我有这样的hashmap:
HashMap<String,Integer> map = new HashMap<String,Integer>();
map.put("java",4);
map.put("go",2);
map.put("objective-c",11);
map.put("c#",2);
Run Code Online (Sandbox Code Playgroud)
现在我想按键长度排序这个映射,如果两个键长度相等(例如go和c#都是长度2),那么按照alphba顺序排序.所以我期望得到的结果是这样的:
打印结果:objective-c,11 java,4 c#,2 go,2
这是我自己的玩具,但它根本不起作用......
HashMap<String,Integer> map = new HashMap<String,Integer>();
map.put("java",4);
map.put("go",2);
map.put("objective-c",11);
map.put("c#",2);
Map<String,Integer> treeMap = new TreeMap<String, Integer>(
new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
return s1.length().compareTo(s2.length());
}
}
);
Run Code Online (Sandbox Code Playgroud)
实际上'compareTo'方法显示为红色(无法编译)....请有人帮我一些代码示例...我有点困惑如何使用比较器类来自定义比较对象...
我正试图从相机捕捉视频帧并UIImageView
实时显示图像泛滥.我试着适应AVCaptureVideoDataOutputSampleBufferDelegate
我的viewcontroller
.我也实现了captureOutput
,但从captureOutput
未被调用过.
这是我的代码:
import UIKit
import AVFoundation
class ViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet var cameraView: UIView!
var selectedImage :UIImage!
let captureSession = AVCaptureSession()
var captureDevice : AVCaptureDevice?
var videoCaptureOutput : AVCaptureVideoDataOutput!
override func viewDidLoad() {
super.viewDidLoad()
captureSession.sessionPreset = AVCaptureSessionPresetLow
self.captureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
if(captureDevice != nil){
beginSession()
}
}
func beginSession() {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), {
self.videoCaptureOutput = AVCaptureVideoDataOutput()
self.videoCaptureOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey:kCVPixelFormatType_32BGRA]
self.videoCaptureOutput.alwaysDiscardsLateVideoFrames = true
self.captureSession.addOutput(self.videoCaptureOutput)
var err …
Run Code Online (Sandbox Code Playgroud) 我要实现的目标是:当我点击特定的UIImageView时,UITapGesture会将字符串传递到tap方法中。
我的代码如下:假设我已经有一个UIImageView对象,当我点击此图像时,它将打个电话,
UITapGestureRecognizer *tapFirstGuy = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(makeCallToThisPerson:@"1234567")];
[imageViewOne addGestureRecognizer:tapFirstGuy];
- (void)makeCallToThisPerson:(NSString *)phoneNumber
{
NSString *phoneNum = [NSString stringWithFormat:@"tel:%@", phoneNumber];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNum]];
}
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下编译错误: @selector(makeCallToThisPerson:@"1234567");
我不知道发生了什么事。为什么不能将字符串传递给private方法?
我目前正在用故事书实现一个 React 定制输入组件。我希望实现的是这个定制的输入组件将需要几个参数,其中一个参数是onChangeInput
,稍后它将负责为“输入值”设置状态值,下面是我的主要输入组件实现:
输入.tsx
import React from 'react'
export type Props = {
/**
* This is the Label text value
*/
labelText?: string,
/**
* Placeholder text for input
*/
placeholder?: string,
/**
* Classes defined here will be appended to the input's default classes
*/
className?: string,
/**
* Value attribute of Input
*/
value?: string,
/**
* Name attribute of Input
*/
name?: string,
/**
* Label for attribute
*/
htmlFor?: string,
/**
* Callback …
Run Code Online (Sandbox Code Playgroud) 我正在做这样的事情:首先,在启动时,"接受"按钮被禁用,用户必须阅读文本视图区域中的条款和条件,然后启用接受按钮.这是我的代码到目前为止,有人能给我一些建议吗?
- (IBAction)acceptAction:(id)sender {
if ([self.termConditionTextView scrollsToTop] == true) {
[acceptButtonOutlet setEnabled:NO];
[[[UIAlertView alloc] initWithTitle:@"Term & Condition" message:@"Please read term & condition first. Thank you." delegate:nil cancelButtonTitle:@"Back" otherButtonTitles:nil] show];
} else {
[acceptButtonOutlet setEnabled:YES];
}
}
Run Code Online (Sandbox Code Playgroud) ios ×4
objective-c ×4
android ×2
iphone ×2
boolean ×1
capture ×1
comparator ×1
database ×1
download ×1
gesture ×1
hashmap ×1
java ×1
json ×1
nsdata ×1
nsdictionary ×1
nsstring ×1
pdf ×1
printing ×1
react-hooks ×1
reactjs ×1
selector ×1
sorting ×1
sql ×1
sqlite ×1
storybook ×1
swift ×1
treemap ×1
typescript ×1
use-state ×1
whitespace ×1