小编pab*_*ros的帖子

如何将这个日期代码转换为swift?

我在Objective-C中有这个代码:

NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd-HH-mm-ss"];
NSString* dateTimePrefix = [formatter stringFromDate:[NSDate date]];
Run Code Online (Sandbox Code Playgroud)

我正在尝试转换为Swift,但我不知道这是我尝试的任何行:

var formatter = NSDateFormatter()
formatter.dateFormat="yyyy-MM-dd-HH-mm-ss"
var dateTimePrefix : NSString
dateTimePrefix = formatter.stringFromDate(formatter as? NSData)
Run Code Online (Sandbox Code Playgroud)

我收到错误stringFromDate.问题是什么?

swift xcode6

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

将字符串从编辑文本传递到另一个活动

我在这里看了一下堆栈溢出的例子.但是,我无法获得正常工作的解决方案.我的应用程序仍然崩溃.如何将字符串从一个活动中的编辑文本传递到另一个活动?

这是我第一个活动的代码:

Button btnGo = (Button) findViewById(R.id.btnGo);

btnGo.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        EditText etLocation = (EditText) findViewById(R.id.et_location);
        Intent intent = new Intent();
        intent.putExtra("location", etLocation.getText().toString());
        startActivity(intent);
    }
}
Run Code Online (Sandbox Code Playgroud)

第二活动代码:

textView1 = (TextView) findViewById(R.id.textView1);

Intent intent = getIntent();
String str = intent.getStringExtra("location");
textView1.setText(str);
Run Code Online (Sandbox Code Playgroud)

android android-edittext android-activity

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

可可豆:没有这样的文件或目录

我已经有一个cocoapod以前可以正常工作的项目,但是现在尝试添加新文件时却以某种方式可以正常工作。我正在错误以下。

/ Users /用户名/.podenv/libexec/../libexec/podenv-exec:第31行:/Users/username/.podenv/versions/1.0.1/bin/pod:无此类文件或目录

我试图删除MyProject.xcworkspacePodfile以便我可以重新安装,Podfile但再次遇到上述错误。

ios cocoapods swift cocoapods-1.0.1

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

如何安装特定版本的 cocoapods repo

这是我的Podfile

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'RMQClient', '~> 0.8'
Run Code Online (Sandbox Code Playgroud)

当我尝试从 cocoapods 安装 repo 时pod install,它会为我安装一个新版本pod 'RMQClient'(例如 0.9)。

在另一个xcode project相同的Podfile,我做了一个pod update和它更新 pod repo 的 cocoapods:

安装 RMQClient 0.9.0(原为 0.8)

cocoapods当我进行更新时,如何防止更新 pod 存储库?如何强制安装我在Podfile.

ios cocoapods

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

如何跟踪使用 NSIndexPath 选择的单元格?

我有多个部分UITableView,每个部分都有不同数量的UITableViewCells.

我想跟踪为每个部分选择的单元格并为已选择的单元格显示图像。

所以我在考虑将它们存储在一个数组中:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
     someArray.append(indexPath)
}
Run Code Online (Sandbox Code Playgroud)

然后显示已选择单元格的图像:

 for indices in self.someArray {
     if indices == indexPath {
         cell.button.setImage(UIImage(named: "selected"), forState: UIControlState.Normal)
     } else {
         cell.button.setImage(UIImage(named: "unselected"), forState: UIControlState.Normal)
     }
 }
Run Code Online (Sandbox Code Playgroud)

我还想使每个部分一次只能选择一个单元格,并且每个部分的每个选择都保持不变。

选择只是不保持原样。每次我在部分 0 中为某行进行选择时,它也会为我的其他部分选择相同的行索引。

我该如何解决?

uitableview ios swift

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