我正在使用Xcode 8.2.1和Swift 3.我有一个包含UITextView的自定义UITableViewCell.当我输入时textView
,自定义单元格会自动增长.这部分工作正常.当我输入特定单元格时,我还想用相同的数据更新我的其他单元格.例如:
当我在第5个单元格中键入文本时,会自动在第11,15和18个单元格中输入相同的数据.这些细胞也必须自动生长.我已经将数据添加到数组的特定索引中.但它没有反映在tableView
.我如何实现此功能?
请仔细阅读我迄今为止实施的以下代码.此updateCellHeight
方法是自定义委托方法.当用户键入时调用此方法textView
.
func updateCellHeight(indexPath: IndexPath, comment: String) {
let currentCellLyricVal = self.traduzioneArray[indexPath.row]["rics"]
tempIndexArray.removeAll()
for (index,element) in traduzioneArray.enumerated() {
let lyricVal = element["rics"]
if currentCellLyricVal == lyricVal {
tempIndexArray.append(index)
}
}
for index in tempIndexArray {
self.traduzioneArray[index]["ione"] = comment
self.lyricsTableView.beginUpdates()
self.lyricsTableView.endUpdates()
}
}
func textViewDidChange(_ textView: UITextView) {
self.delegate.updateCellHeight(indexPath: self.cellIndexPath, comment: textView.text)
}
Run Code Online (Sandbox Code Playgroud) 我正在和一个人一起工作UICollectionView
.按照dequeueReusableCell(withReuseIdentifier:for:)
预期在调用此方法之前必须使用该register(_:forCellWithReuseIdentifier:)
方法注册类或nib文件,我在我的viewDidLoad
func中添加了一行作为
self.collectionView!.register(PhotoCollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
Run Code Online (Sandbox Code Playgroud)
现在,当我使用单元格进行出列和配置时,我收到错误和应用程序崩溃.
致命错误:在展开Optional值时意外发现nil
这是我的DataSource方法:
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier,
for: indexPath) as! PhotoCollectionViewCell
let aPhoto = photoForIndexPath(indexPath: indexPath)
cell.backgroundColor = UIColor.white
cell.imageView.image = aPhoto.thumbnail //this is the line causing error
return cell
}
Run Code Online (Sandbox Code Playgroud)
这是我的PhotoCollectionViewCell
课
class PhotoCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var imageView: UIImageView! //I double checked this IBOutlet whether it connects …
Run Code Online (Sandbox Code Playgroud) 我正在尝试设置我的应用程序以使用MPRemoteCommandCenter.我从文档编程指南中得到了这个例子.我导入AVFoundation甚至尝试导入AVKIT,我收到错误使用未解析的标识符'MPRemoteCommandCenter'.当我创建MPRemoteCommandCenter.shared()的实例时.任何帮助,将不胜感激.
func setupRemoteTransportControls() {
// Get the shared MPRemoteCommandCenter
let commandCenter = MPRemoteCommandCenter.shared() Error //**Use of unresolved identifier 'MPRemoteCommandCenter'**
// Add handler for Play Command
commandCenter.playCommand.addTarget { [unowned self] event in
if self.audioPlayer.rate == 0.0 {
self.audioPlayer.play()
return .success
}
return .commandFailed
}
// Add handler for Pause Command
commandCenter.pauseCommand.addTarget { [unowned self] event in
if self.audioPlayer.rate == 1.0 {
self.audioPlayer.pause()
return .success
}
return .commandFailed
}
}
Run Code Online (Sandbox Code Playgroud) 我注意到通知上的标题是应用程序显示名称,强制全部大写。
客户的应用程序名称是大写和小写的混合,这是他们品牌的一部分。他们希望这个名字尊重混合的大写/小写。
有没有人知道更改通知中显示的文本的方法,或者我们是否坚持使用大写版本的应用程序显示名称?
有没有办法禁用特定的选择器项目?在 AppKit 中,您可以NSPopUpButton
通过NSMenuValidation
协议禁用项目,但可以预见,禁用选择器中的标签不会产生任何影响。只是 SwiftUI 中的另一个 API 差距?
我试过:
Picker(selection: $viewModel.providerSelection, label: Text("Try using:")) {
ForEach(0..<Provider.allCases.count) {
Text(Provider.allCases[$0].rawValue.capitalized)
.disabled(true)
}
}
Run Code Online (Sandbox Code Playgroud)
禁用和不在这里之间没有视觉或交互差异。
我有一个图像集,其方向(语言方向)属性设置为Left to Right
. 这意味着对于从右到左的语言(即:阿拉伯语、希伯来语),图像应该水平镜像。
现在,如果我将此图像设置在UIImageView
from 上Storyboard
,则该图像不会针对 RTL 语言进行镜像。见下图:
当我没有
imageView
从情节提要中设置图像而是在代码中加载图像并将其设置为imageView
的图像属性时, 图像会被镜像到 RTL 语言。见下图:
但同样,如果我
imageView
从情节提要中设置图像并在代码中加载图像并将其设置为imageView
's image 属性,则该 图像不会针对 RTL 语言进行镜像。见下图:
只有 Storyboard有什么问题?为什么当图像从 Storyboard 和代码同时设置时代码不能覆盖行为?
我是 iOS 开发新手,需要在 iOS 地图中实现可拖动注释。我的代码如下。无论我做什么,我都无法获得可拖动的注释,之后我需要获取引脚指向的位置的地址,任何人都可以帮助注释
RegistrationViewController.swift
class RegistrationViewController: UIViewController,UIPickerViewDelegate,UIPickerViewDataSource,MKMapViewDelegate{
@IBOutlet weak var mapView: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
var centerLocation = CLLocationCoordinate2DMake(12.964370125970357, 77.59643554937497)
var mapspan = MKCoordinateSpanMake(0.01, 0.01)
var mapregion = MKCoordinateRegionMake(centerLocation, mapspan)
self.mapView.setRegion(mapregion, animated: true)
let pin = pinAnnotation(title:"hello",subtitle:"how are you",coordinate:centerLocation)
mapView.addAnnotation(pin)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {
if annotation is MKPointAnnotation {
let pinAnnotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "myPin")
pinAnnotationView.pinColor = .purple
pinAnnotationView.isDraggable = true
pinAnnotationView.canShowCallout = …
Run Code Online (Sandbox Code Playgroud) 抱歉,标题不清楚。
我的意思是:如果我有一个变量,我们将其称为a,其值为“ Hello \ nWorld”,它将写为
var a = "Hello\nWorld
Run Code Online (Sandbox Code Playgroud)
如果我要打印它,我会得到
Hello
World
Run Code Online (Sandbox Code Playgroud)
我如何将其打印为:
Hello\nWorld
Run Code Online (Sandbox Code Playgroud) 我有以下两个数组:
let xaxis = ["monday", "tuesday", "wednesday", "thursday", "friday"]
let yaxis = [1, 2, 3, 4, 5]
Run Code Online (Sandbox Code Playgroud)
我想将它们合并到一个如下所示的数组中:
[ ("monday", 1), ("tuesday", 2), ("wednesday", 3), ("thursday", 4), ("friday", 5)]
Run Code Online (Sandbox Code Playgroud) 我已经被逼疯了好几个小时了,因为我无法解决这个问题。
我有一个集合视图,它可以有不同的部分和不同的编号。每个中的项目数。对于每个部分,我需要使用不同类型的节标题。因此,为此,我将使用UICollectionReusableView
. 但我似乎无法成功地UICollectionReusableView
通过UINib
注册方式使用自定义子类。
当我将可重用视图向下转换为我的子类时,会发生崩溃。喜欢:
let friendHeader = collectionView.dequeueReusableSupplementaryView(ofKind: kind,
withReuseIdentifier: "FriendHeaderView",
for: indexPath) as! FriendHeaderView
Run Code Online (Sandbox Code Playgroud)
下面是代码片段:
class ViewController: UIViewController {
@IBOutlet weak var collectionView: UICollectionView!
private let viewModel = ProfileViewModel()
override func viewDidLoad() {
super.viewDidLoad()
collectionView.dataSource = self
collectionView.delegate = self
// more code
collectionView.register(UINib(nibName: "FriendHeaderView", bundle: nil),
forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader,
withReuseIdentifier: "FriendHeaderView")
}
}
Run Code Online (Sandbox Code Playgroud)
现在这是数据源的实现:
extension ViewController: UICollectionViewDataSource {
func numberOfSections(in collectionView: UICollectionView) -> Int {
// valid implementation
}
func collectionView(_ collectionView: UICollectionView, …
Run Code Online (Sandbox Code Playgroud) swift ×9
ios ×6
uitableview ×2
avfoundation ×1
iphone ×1
macos ×1
mapkit ×1
mkannotation ×1
swiftui ×1
tuples ×1
uiimageasset ×1
uiimageview ×1
uistoryboard ×1