我有一些HTML数据,其中包含标题,段落,图像和列表标签.
有没有办法在一个UITextView或中显示这些数据UILabel?
我使用UICollectionView(flowlayout)来构建一个简单的布局.每个单元格的宽度设置为使用的屏幕宽度self.view.frame.width
但是当我旋转设备时,单元格不会更新.
我找到了一个函数,在调整方向时调用它:
override func willRotateToInterfaceOrientation(toInterfaceOrientation:
UIInterfaceOrientation, duration: NSTimeInterval) {
//code
}
Run Code Online (Sandbox Code Playgroud)
但我无法找到更新UICollectionView布局的方法
主要代码在这里:
class ViewController: UIViewController , UICollectionViewDelegate , UICollectionViewDataSource , UICollectionViewDelegateFlowLayout{
@IBOutlet weak var myCollection: UICollectionView!
var numOfItemsInSecOne: Int!
override func viewDidLoad() {
super.viewDidLoad()
numOfItemsInSecOne = 8
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func willRotateToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
//print("orientation Changed")
}
func …Run Code Online (Sandbox Code Playgroud) 我有一个案例,我必须重新加载一个高度UITableViewCell.
但如果我调用该函数
tableView.reloadRowsAtIndexPaths([NSIndexPath(forRow: webView.tag, inSection: 0)], withRowAnimation: .Automatic)
Run Code Online (Sandbox Code Playgroud)
它重新加载高度以及单元格的数据.我怎样才能控制Swift中单元格的高度?
这是我的cellForRow块:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let cell = tableView.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath) as! CustomTableViewCell1
cell.heading.text = headerText
return cell
}
else if indexPath.row == 1 {
let cell = tableView.dequeueReusableCellWithIdentifier("cell2", forIndexPath: indexPath) as! CustomTableViewCell2
ImageLoader.sharedLoader.imageForUrl(self.headerImage , completionHandler:{(image: UIImage?, url: String) in
cell.mainImage.image = image
})
return cell
}
else if indexPath.row == 2 {
let cell = …Run Code Online (Sandbox Code Playgroud) 我已经实现了一个RPScreenRecorder记录屏幕和麦克风音频.多次录制完成后,我停止录制并使用视频合并Audios,AVMutableComposition然后将所有视频合并为单视频.
对于屏幕录制和获取视频和音频文件,我正在使用
- (void)startCaptureWithHandler:(nullable void(^)(CMSampleBufferRef sampleBuffer, RPSampleBufferType bufferType, NSError * _Nullable error))captureHandler completionHandler:
Run Code Online (Sandbox Code Playgroud)
用于停止录制.我叫这个功能:
- (void)stopCaptureWithHandler:(void (^)(NSError *error))handler;
Run Code Online (Sandbox Code Playgroud)
这些都很直接.
大部分时间它都很棒,我收到视频和音频CMSampleBuffers.但有时会发生这种情况,startCaptureWithHandler只发送音频缓冲区但不发送视频缓冲区.
一旦我遇到这个问题,它将不会发生,直到我重新启动我的设备并重新安装应用程序.这使我的应用程序对用户来说不可靠.我认为这是一个重播工具包问题,但无法与其他开发人员发现相关问题.如果你们中的任何一个遇到这个问题并得到解决方案,请告诉我.
我已多次检查但未在配置中看到任何问题.但无论如何它在这里.
NSError *videoWriterError;
videoWriter = [[AVAssetWriter alloc] initWithURL:fileString fileType:AVFileTypeQuickTimeMovie
error:&videoWriterError];
NSError *audioWriterError;
audioWriter = [[AVAssetWriter alloc] initWithURL:audioFileString fileType:AVFileTypeAppleM4A
error:&audioWriterError];
CGFloat width =UIScreen.mainScreen.bounds.size.width;
NSString *widthString = [NSString stringWithFormat:@"%f", width];
CGFloat height =UIScreen.mainScreen.boNSString *heightString = [NSString stringWithFormat:@"%f", height];unds.size.height;
NSDictionary * videoOutputSettings= @{AVVideoCodecKey : AVVideoCodecTypeH264,
AVVideoWidthKey: widthString,
AVVideoHeightKey : heightString};
videoInput = [[AVAssetWriterInput alloc] initWithMediaType:AVMediaTypeVideo outputSettings:videoOutputSettings]; …Run Code Online (Sandbox Code Playgroud) 我是swift的初学者,我遇到过需要在循环中运行AlamoFire GET请求的情况.但据我所知,Alamofire Get请求是一个异步调用,并在循环中调用它将创建许多线程.
要求是:
必须在循环中遍历数组
必须通过AlamoFire GET请求调用每个索引上的URL
通过请求接收的数据将被添加到数据数组中
将最后一个数据保存在数组中后,应调用CollectionView.reload调用
伪代码如下:
for bookmarkURL in bookmarks
Alamofire.request(.GET, bookmarkURL ).responseJSON
{ response in switch response.result {
case .Success(let JSON):
x[i] = JSON as! [String : AnyObject] // saving data
case .Failure(let error):
print("the error for \(self.bookmarkURL) is \(error) ")
}
i++
if i == bookmarks.count{
collectionView.reload()
break}
}
Run Code Online (Sandbox Code Playgroud)
谁能告诉我怎么按顺序做呢?
我是 mac OS 开发的新手,所以请原谅我的任何基本问题,但相信我,我已经做了很多研究,但仍然有点卡住。
所以我试图访问当前用户的桌面内容。
在操场上很容易,只需使用
let homeURL = FileManager.default.homeDirectoryForCurrentUser
let desktopURL = homeURL.appendingPathComponent("Desktop/")
let contents = try fileManager.contentsOfDirectory(atPath:desktopURL.path)
Run Code Online (Sandbox Code Playgroud)
它显示桌面上的所有内容。但是当我在一个项目中运行类似的代码时。
let homeURL = FileManager.default.homeDirectoryForCurrentUser
Run Code Online (Sandbox Code Playgroud)
它返回我的应用程序的容器。
file:///Users/myUserName/Library/Containers/AppIdentifier/Data/
并且
let contents = try fileManager.contentsOfDirectory(atPath: desktopURL.path)不会返回任何内容。
好吧,我然后我用
删除最后一个路径组件
同时获取主路径以获取我的 URL 直到我的用户名
let homeURL = FileManager.default.homeDirectoryForCurrentUser.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent()
Run Code Online (Sandbox Code Playgroud)
当我调试它时,它返回
file:///Users/myUserName
如我所愿。但是当我运行代码时,内容变量仍然为零。
下一次尝试:
我在互联网上搜索以检查获取目录路径的替代方法。所以我遇到了
NSOpen面板
我从 Panel 获取文件夹的 URL 并使用该 URL 检查其中的内容。它工作正常
这是代码
let homeURL = FileManager.default.homeDirectoryForCurrentUser
let desktopURL = homeURL.appendingPathComponent("Desktop/")
let contents = try fileManager.contentsOfDirectory(atPath:desktopURL.path)
Run Code Online (Sandbox Code Playgroud)
但我不明白为什么我不能直接访问内容。我已经尝试了很多次。在项目中,我无法enter code here直接从(某种)硬编码 URL 获取内容。
如果需要任何其他信息,请告诉我。
swift ×5
ios ×4
alamofire ×1
app-store ×1
arrays ×1
asynchronous ×1
flowlayout ×1
html ×1
localization ×1
macos ×1
replaykit ×1
uitableview ×1
uitextview ×1
xcode ×1