如果我将resign代码放在我的if条件下键盘不会退出,如果我评论if条件我的键盘辞职.
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
if (searchText.length == 0) {
[searchBar resignFirstResponder];
}
}
Run Code Online (Sandbox Code Playgroud)
我想在用户按下"x"按钮时退出键盘,这时UISearchBar文本为空.有没有办法做到这一点?
我成功地实现了UICollectionView在屏幕上显示一些虚拟文本的功能。一切工作正常,现在我添加了拖动功能实现self.collectionView.dragDelegate = self和UICollectionViewDelegateFlowLayout,但它不起作用。我还缺少什么吗?
final class XptoComponent: UIView {
private var titles = ["Xpto 1", "Xpto 2", "Xpto 3", "Xpto 4", "Xpto 5", "Xpto 6", "Xpto 7", "Xpto 8", "Xpto 9"]
private var collectionView: UICollectionView = {
let collectionViewLayout = UICollectionViewFlowLayout()
collectionViewLayout.minimumInteritemSpacing = 0
collectionViewLayout.minimumLineSpacing = 0
collectionViewLayout.itemSize = CGSize(width: UIScreen.main.bounds.size.width, height: NumericConstant.ViewCell.height)
collectionViewLayout.sectionInset = .zero
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: collectionViewLayout).usingAutoLayout()
collectionView.registerCell(XptoCollectionViewCell.self)
return collectionView
}()
init() {
super.init(frame: .zero)
self.collectionView.dataSource = self
self.collectionView.delegate …Run Code Online (Sandbox Code Playgroud) drag-and-drop ios uicollectionview swift uicollectionviewdragdelegate
我正在进行单元测试,并尝试从 获取文件bundle,但在网上let bundle = Bundle(for: type(of: SecCertificate)我收到错误:
无法将类型“SecCertificate.Type.Type”的值转换为预期参数类型“AnyClass”(又名“AnyObject.Type”)
enum CertificatesMock: CertificatesType {
case myWebUrl
var host: [String] {
switch self {
case .myWebUrl:
return ["https://my.web.url/"]
}
}
var certificates: SecCertificate {
switch self {
case .myWebUrl:
let bundle = Bundle(for: type(of: SecCertificate))
return CertificatesMock.certificate(filename: "myWebUrl", bundle: bundle)
}
}
private static func certificate(filename: String, bundle: Bundle) -> SecCertificate {
if let filePath = bundle.path(forResource: filename, ofType: "cer") {
do {
let data = try Data(contentsOf: URL(fileURLWithPath: …Run Code Online (Sandbox Code Playgroud) 我见过使用它的相似代码,但我在这一行给了我这个错误“无法解析 URLEncoder”:
String paramString = p.getName() + "=" + URLEncoder.encode(p.getValue(),"UTF-8");
它说函数是 encode(String s, String enc) 在“enc”上它说要使用的编码方案。
我正在运行 Eclipse SDK 版本:3.6.1,但我不知道如何解决此错误。
是否可以使用MapKit在iPhone中显示地图,就像我正在做的那样,在地图上显示缩放控件?
如果没有,我应该使用什么标志或方法来增加和减少缩放,所以我可以创建方法,只需按一下按钮即可完成.
为什么我必须给我的rigthAnchor约束一个负值才能titleLabel从视图的右侧产生 28 个边距。如果我只是给它正值,它会超出视图 28 个像素。
private func setupLayout() {
view.addSubview(imageView)
view.addSubview(titleLabel)
// *** imageView ***
if #available(iOS 11.0, *) {
imageView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 116).isActive = true
} else {
imageView.topAnchor.constraint(equalTo: view.topAnchor, constant: 116).isActive = true
}
imageView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
imageView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
imageView.heightAnchor.constraint(equalToConstant: 224).isActive = true
// *** titleLabel ***
titleLabel.topAnchor.constraint(equalTo: imageView.bottomAnchor, constant: 25).isActive = true
titleLabel.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -28).isActive = true
titleLabel.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 28).isActive = true
}
Run Code Online (Sandbox Code Playgroud) 我在代码审查中被要求进行此更新。
从:
func bind(errorText: Driver<String>) {
errorText.drive(onNext: { [weak self] text in
self?.set(text: text)
self?.accessibilityValue = text
}).disposed(by: disposeBag)
}
Run Code Online (Sandbox Code Playgroud)
到:
func bind(errorText: Driver<String>) {
errorText.drive(onNext: { [weak self] text in
guard let self = self else { return }
self.set(text: text)
self.accessibilityValue = text
}).disposed(by: disposeBag)
}
Run Code Online (Sandbox Code Playgroud)
区别在于self?和 之间guard。
在第一个代码中,我的印象是self?当它调用的变量为零时被释放。或者是第二种方式,使用guard let self100% 确保self发布的方式?谢谢
这种情况正在发生,我无法理解为什么
User-MBP:Project user$ git status
On branch playlist
Your branch is ahead of 'origin/playlist' by 1 commit.
(use "git push" to publish your local commits)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: Project.xcodeproj/xcuserdata/user.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
modified: Project/TPSettings.plist
no changes added to commit (use "git add" and/or "git commit -a")
User-MBP:Project user$ cat .gitignore
SubModules/
.DS_Store
Project.xcodeproj/project.xcworkspace/xcuserdata/user.xcuserdatad/UserInterfaceState.xcuserstate
Project.xcodeproj/xcuserdata/user.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
User-MBP:Project user$
Run Code Online (Sandbox Code Playgroud)
该文件是在.gitignore所以它不应该告诉我提交文件.
我有以下号码
7.9775609756097534
我正在使用下面的代码只显示两位小数
let formatted = String(format: "Angle: %.2f", angle)
Run Code Online (Sandbox Code Playgroud)
问题是结果是:
7.98
代替
7.97
swift ×5
ios ×4
xcode ×4
anchor ×1
android ×1
bundle ×1
closures ×1
constraints ×1
eclipse ×1
git ×1
github ×1
http-post ×1
iphone ×1
map ×1
objective-c ×1
rest ×1
self ×1
string ×1
uicollectionviewdragdelegate ×1
uikeyboard ×1
uisearchbar ×1
unit-testing ×1
zoom ×1
zooming ×1