我有一个带字典的数组示例:
(
{
Email = "kate-bell@mac.com";
Name = "Kate Bell";
Number = "(555) 564-8583";
},
{
Email = "d-higgins@mac.com";
Name = "Daniel Higgins";
Number = "555-478-7672";
}
)
Run Code Online (Sandbox Code Playgroud)
我想根据密钥"名称"过滤这个字典
func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
let predicate = NSPredicate(format:"Name == %@", searchText)
let filteredArray = (arrContact as NSMutableArray).filteredArrayUsingPredicate(predicate)
print(filteredArray)
if(filteredArray.count == 0){
searchActive = false;
} else {
searchActive = true;
}
tblData.reloadData()
}
Run Code Online (Sandbox Code Playgroud)
我总是从上面的swift代码得到空数组.请帮我解决这个问题.谢谢
nsmutablearray uisearchbar nsmutabledictionary nspredicate swift2
所以我有这个UITableView单元格有4个UITextField,我想在按钮点击时得到它们的值.
此代码不检索任何值.
@IBAction func printBtnAction(_ sender: Any) {
let cell = self.myTableView.dequeueReusableCell(withIdentifier: "manualAddC1") as! AddFriendC1Cell
let alias = cell.aliasTextField.text!
let primaryPhone = cell.primaryPhoneTextField.text!
let secondaryPhone = cell.seondaryPhoneTextField.text!
let email = cell.emailAddressTextField.text!
print("Alias: \(alias), Phone: \(primaryPhone), Phone2: \(secondaryPhone), Email: \(email)")
}
Run Code Online (Sandbox Code Playgroud)
目前我正在使用底部有四个控件的对话视图.每个控件都在对话框中加载不同的视图.其中一个控件是AVPlayer在对话视图中设置并正在播放它.不幸的是,AVPlayer它本身没有播放控件.
该AVPlayerViewController怎么过确实有播放控制.是否有可能将一个 AVPlayerViewController 内部的 UIView ,这样它不会开始作为一个新的屏幕? 我想把它放在我的内部,UIView所以一切都发生在我的拨号内.
我正在使用AlamofireImage库,我想subview在ImageView上添加一个(UIActivityIndicator),直到图像没有下载.但不知道该怎么做.
self.imgView_main.af_setImageWithURL(downloadURL)
Run Code Online (Sandbox Code Playgroud)
图像正在下载.但如何表明UIActivityIndicator请帮助我
我有扩展名将html符号转换为字符串:
extension String {
func convertHtmlSymbols() throws -> String? {
guard let data = data(using: .utf8) else { return nil }
return try NSAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue], documentAttributes: nil).string
}
}
Run Code Online (Sandbox Code Playgroud)
这个扩展很好.但是我需要将此扩展转换为类"Converter"中的函数:
class Converter{
func convertHtmlSymbols(data: String) throws -> String? {
guard let data = data(using: .utf8) else { return nil }
return try NSAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue], documentAttributes: nil).string
}
}
Run Code Online (Sandbox Code Playgroud)
但我得到了这个错误:
错误:无法调用非函数类型的值
我正在尝试在应用处于活动状态时显示横幅通知.我使用了给定的方法但没有结果,横幅通知仅在应用关闭时出现:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
print("Push notification received: \(userInfo)")
if application.applicationState == .active {
print("active")
let localNotification = UILocalNotification()
localNotification.userInfo = userInfo
localNotification.alertAction = "Test"
localNotification.soundName = UILocalNotificationDefaultSoundName
localNotification.alertBody = "Notification test!!"
localNotification.fireDate = Date()
UIApplication.shared.scheduleLocalNotification(localNotification)
}
}
Run Code Online (Sandbox Code Playgroud)
它打印"活动"但通知未显示.我错过了任何一步吗?
谢谢.
我有一个MainViewController,它有一个容器视图.边缘边缘很少.
现在我导航到另一个视图ViewController1.假设我在ViewController1中的某个区域出现错误.然后我想用红色改变我的MainViewController的背景.因此视图应如下所示(屏幕截图已附加),其中红色边框为MainViewController背景
这是我的代码
class ViewController1: UIViewController {
var MainVC = MainViewController()
override func viewDidLoad() {
super.viewDidLoad()
MainVC.view.backgroundColor = UIColor.redColor()
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用
swift ×6
ios ×4
swift3 ×3
xcode ×2
avplayer ×1
iphone ×1
nspredicate ×1
swift2 ×1
uisearchbar ×1
uitableview ×1