小编Luc*_*arr的帖子

搜索元素的后代

量角器什么是选择子元素的最佳方式?假设我们有以下布局......

<div id='parent_1'>
    <div class='red'>Red</div>
    <div class='blue'>Blue</div>
</div>
<div id='parent_2'>
    <div class='red'>Red</div>
    <div class='blue'>Blue</div>
</div>
Run Code Online (Sandbox Code Playgroud)

使用jQuery,我们会做这样的事情.

var p1 = $('#parent_1');
var p1_red = $('.red', p1);  //or p1.find('.red');
var p1_blue = $('.blue', p1); //or p1.find('.blue');
Run Code Online (Sandbox Code Playgroud)

但是使用Protractor,首先获得父元素是否有意义?因为这样做var p1 = element('#parent_1');实际上不会检索/搜索对象,直到getText()调用它为止.

这样做..

场景1

expect(p1.element('.red')).toBe('red');
expect(p1.element('.blue')).toBe('blue');
Run Code Online (Sandbox Code Playgroud)

要么

情景2

expect(element('#parent_1').element('.red')).toBe('red');
expect(element('#parent_1').element('.blue')).toBe('blue');
Run Code Online (Sandbox Code Playgroud)

要么

场景3

expect(element('#parent_1 > .red')).toBe('red');
expect(element('#parent_1 > .blue')).toBe('blue');
Run Code Online (Sandbox Code Playgroud)

一种方法相对于另一种方法有什么好处吗?

这就是我正在做的事情,但我不知道将父母与cssSelector分开是否有任何好处:

function getChild(cssSelector, parentElement){
    return parentElement.$(cssSelector);
}

var parent = $('#parent_1');
var child_red = getChild('.red', parent);
var child_blue = getChild('.blue', parent); …
Run Code Online (Sandbox Code Playgroud)

element parent-child chaining protractor

46
推荐指数
1
解决办法
4万
查看次数

如何使用单选复选框android在AlertDialog中选择一个条目?

我有一个警告对话框,其中包含一个选项列表和两个按钮:一个OK按钮和一个cancel按钮.下面的代码显示了我是如何实现它的.

private final Dialog createListFile(final String[] fileList) {
  AlertDialog.Builder builder = new AlertDialog.Builder(this);
  builder.setTitle("Compare with:");

  builder.setSingleChoiceItems(fileList, -1, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
      Log.d(TAG,"The wrong button was tapped: " + fileList[whichButton]);
    }
  });

  builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {}
  });

  builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {}
  });

  return builder.create();
}
Run Code Online (Sandbox Code Playgroud)

我的目标是在点击按钮时获取所选单选按钮的名称OK.我试图将字符串保存在变量中,但在内部类中,可以只访问最终变量.有没有办法避免使用最终变量来存储选定的单选按钮?

android android-alertdialog

40
推荐指数
4
解决办法
8万
查看次数

增加uitableviewcell高度同时增加内部UITextView

我创建了一个UITableView具有不同类型UITableViewCell的内容,具体取决于要显示的内容类型.其中一个是以这种方式UITableViewCellUITextView编程方式创建的内部:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  ...
  if([current_field.tipo_campo isEqualToString:@"text_area"])
  { 
    NSString *string = current_field.valore;
    CGSize stringSize = [string sizeWithFont:[UIFont boldSystemFontOfSize:15] constrainedToSize:CGSizeMake(320, 9999) lineBreakMode:UILineBreakModeWordWrap];
    CGFloat height = ([string isEqualToString:@""]) ? 30.0f : stringSize.height+10;
    UITextView *textView=[[UITextView alloc] initWithFrame:CGRectMake(5, 5, 290, height)];
    textView.font = [UIFont systemFontOfSize:15.0];
    textView.text = string;
    textView.autoresizingMask =  UIViewAutoresizingFlexibleWidth;
    textView.textColor=[UIColor blackColor];
    textView.delegate = self;
    textView.tag = indexPath.section;
    [cell.contentView addSubview:textView];
    [textView release];   
    return cell;
  }
  ...
}
Run Code Online (Sandbox Code Playgroud)

由于文本视图是可编辑的,因此包含它的单元格应更改其高度以正确拟合文本视图大小.最初我通过调整UITextView方法内部来做到这一点textViewDidChange …

objective-c uitableview uitextview ios

13
推荐指数
1
解决办法
8760
查看次数

Http Date to NSDate

我有一个字符串取自http响应标题字段"日期"以这种格式:

"Sun, 24 Jun 2012 16:34:51 GMT"
Run Code Online (Sandbox Code Playgroud)

我想要的是在NSDate对象中转换此字符串.对于此范围,我已NSDateFormatter使用各种格式实例化:

[dateFormatter setDateFormat:@"EEE',' dd' 'MMM' 'yyyy HH':'mm':'ss zzz"];
[dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss zzz"];
[dateFormatter setDateFormat:@"EEE',' dd' 'MMM' 'yyyy HH':'mm':'ss 'GMT'"];
Run Code Online (Sandbox Code Playgroud)

但是当我从日期打印字符串时使用:

[dateFormatter dateFromString:date]
Run Code Online (Sandbox Code Playgroud)

我收到:

(null)
Run Code Online (Sandbox Code Playgroud)

我哪里做错了?

objective-c nsdate nsdateformatter ios

7
推荐指数
1
解决办法
2865
查看次数

如何在cordova相机的成功回调中获取文件对象?

目前我正在使用以下方法,它提供文件的详细信息,但不是实际的对象,它似乎是我们从javascript/jQuery中得到的.有没有人知道如何使用cordova和javascript从移动ios/android文件系统从文件URI /本机URI获取文件对象?

以下是我目前使用的代码段..

window.resolveLocalFileSystemURL(
  filepath,
  function(fileEntry) {
    fileEntry.file(
      function(file) {
        var reader = new FileReader();
        reader.onloadend = function() {
          var imgBlob = new Blob([this.result], {type: "image/jpeg"});
          var uploadedFile = imgBlob;
          uploadedFile.name = file.name;
          alert("Importing Asset from Camera.. " + uploadedFile.name);
          alert(uploadedFile.type);
          alert(uploadedFile.size);
          importAsset(uploadedFile);
        };
        reader.readAsArrayBuffer(file);
      },
      function(error) { alert("Error in fileEntry.file():" + error) })
  },
  function(error) { alert("Error in window.resolveLocalFileSystemURL():" + error) }
);
Run Code Online (Sandbox Code Playgroud)

注意:FileTransfer.upload()在我的情况下不起作用.

我在使用Append图像文件获取表格数据后使用上面的代码- Cordova/Angular在完成#SO的现有问答后

javascript android ios cordova phonegap

7
推荐指数
1
解决办法
435
查看次数

NSNumberFormatter maximumFractionDigits和maximumSignificantDigits错误

在iOS 8 上使用maximumFractionDigitsmaximumSignificantDigits一起使用时这是一个错误NSNumberForamtter吗?

NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.maximumFractionDigits = 2;  
formatter.maximumSignificantDigits = 3;
NSLog(@"%@", [formatter stringFromNumber:@(0.3333)]); // output 0.333 expected 0.33
Run Code Online (Sandbox Code Playgroud)

如果我只使用它,它工作正常 maximumFractionDigits

NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.maximumFractionDigits = 2;
NSLog(@"%@", [formatter stringFromNumber:@(0.3333)]); // output expected .33
Run Code Online (Sandbox Code Playgroud)

nsnumberformatter ios

6
推荐指数
1
解决办法
796
查看次数

用字符串枚举创建Fluent模型

这是我的流利模型

struct Ailment: PostgreSQLModel {

enum Frequency: String , Content {
    case regular = "Regular"
    case occasional = "Occasional"
    case incidentFound = "Incident Found"
}

var id: Int?

var ailment: String

var frequency: Frequency

var dateIdentified: Date?

var underMedication: Bool

var breifDescription: String

}
Run Code Online (Sandbox Code Playgroud)

我可以用创建Fluent模型Int Enum,但不能用String Enum

我低于异常

Fatal error: Error raised at top level: ?? DecodingError: Cannot initialize Frequency from invalid String value 1
Run Code Online (Sandbox Code Playgroud)

提前致谢 :)

fluent vapor

5
推荐指数
1
解决办法
283
查看次数

Swift - POST 请求,使用 Vapor 3 发送 JSON

我在使用 Vapor 3 发送正文包含 JSON 的 POST 请求时遇到问题。我正在使用https://docs.postman-echo.com/来测试它,它使用发送的相同 JSON 进行响应。

我已查看此处的答案,但在编码和内容类型方面出现错误。

router.get("hooray") { req -> Future<View> in

  var postHeaders: HTTPHeaders = .init()
  postHeaders.add(name: .contentType, value: "application/json")
  postHeaders.add(name: .accept, value: "*/*")
  postHeaders.add(name: .acceptEncoding, value: "gzip, deflate")

  let oneField = singleGet(foo: "barfoobar")

  // { foo: "barfoobar" } - JSON string

  let encoder = JSONEncoder()
  encoder.outputFormatting = .prettyPrinted

  let jsonData = try encoder.encode(oneField)
  let jsonString = String(data: jsonData, encoding: .utf8)!
  let postBody = HTTPBody(string: jsonString)

  let httpReq = HTTPRequest(method: …
Run Code Online (Sandbox Code Playgroud)

json http swift vapor

5
推荐指数
0
解决办法
946
查看次数

Android java.lang.NullPointerException:尝试获取null数组的长度

对不起,我的格式化我是Android的新手,以及stackoverflow不能提交我的所有logcat由于一些格式错误

总之,我得到以下错误:

at com.youmasti.mp3test.MainActivity.findsongs(MainActivity.java:45)
at com.youmasti.mp3test.MainActivity.onCreate(MainActivity.java:27)
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

Main Activity

public class MainActivity extends AppCompatActivity {

ListView lv;
String items;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    lv= (ListView)findViewById(R.id.lvPlaylist);
    //File fTest = Environment.getExternalStorageDirectory();
    ArrayList<File> mySongs = findsongs(Environment.getExternalStorageDirectory());

    for (int i = 0; i < mySongs.size(); i++) {
        toast(mySongs.get(i).getName().toString());
    }
}

public ArrayList<File> findsongs(File root) {
    ArrayList<File> al= new ArrayList<File>();
    File[] file= root.listFiles();

    for (File singlefile : file) {
        if (singlefile.isDirectory() && !singlefile.isHidden()) {
            al.addAll(findsongs(singlefile));
        } else {
            if (singlefile.getName().endsWith(".mp3")) { …
Run Code Online (Sandbox Code Playgroud)

java android

4
推荐指数
1
解决办法
2万
查看次数

处理远程通知

我正在阅读如何在开发者Apple指南上处理远程通知.我的问题是两个:这句话的解释是什么

当应用程序未在前台运行时,将传递通知

未在前景覆盖背景中运行且未运行或仅处于后台状态.根据解释,以下句子:

应用程序图标在运行iOS的设备上轻触,应用程序调用相同的方法,但不提供有关通知的信息.

有一种不同的感觉.

第二个问题涉及我连续两次远程通知的情况:当我在方法中打开应用程序时

application:didFinishLaunchingWithOptions:或application:didReceiveRemoteNotification:

我有关于所有通知的信息或只是最后一个?

apple-push-notifications ios

3
推荐指数
1
解决办法
1662
查看次数

Swift 只允许选择一个单元格

我有一个可用的 UITableview,它当前允许选择多个单元格。我只想选择一个,如果选择了前一个,则新选择应取消选中前一个。脑筋急转弯!这是我的代码:

 func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let indexPath = tableView.indexPathForSelectedRow();
    let CurrentCell = tableView.cellForRowAtIndexPath(indexPath!) as UITableViewCell!;

    if CurrentCell.imageView!.image == nil {
        let SelectedCell = CurrentCell.textLabel!.text
        CurrentCell.imageView!.image = UIImage(named:"check")!
        CurrentCell.textLabel!.font = UIFont(name:"OpenSans-Bold", size:15)
        println("Selected Cell is")
        println(SelectedCell)
    } else {
        CurrentCell.imageView!.image = nil
        let SelectedCell = "NothingSelected"
        CurrentCell.textLabel!.font = UIFont(name:"OpenSans-Regular", size:15)    
        println("Nothing Selected")
    }
}
Run Code Online (Sandbox Code Playgroud)

xcode uitableview ios swift

1
推荐指数
1
解决办法
5468
查看次数