草庐IT

encode_cell

全部标签

swift - 如何实现上下文可控的Swift Codable Encode函数?

我正在尝试为Codable结构实现一个编码器,我可以通过传入一个上下文来控制它,该上下文确定我将哪些字段添加到输出JSON中。但我想不出一个好的方法。例如假设我有以下内容:importFoundationstructMyStruct:Encodable{vara:Int=0varb:Int=0enumCodingKeys:String,CodingKey{caseacaseb}enumContext{casesummary,full}//Icanwritesomethinglikethisfuncencode(toencoder:Encoder)throws{varcontainer=

ios - Swift 4.2 UITableView Cell 不会自动改变它的高度

我在自动调整单元格高度时遇到问题。单元格中有一个UILabel,它有一个很长的文本。但是,它是不可见的,因为单元格不会自动变大。importUIKitclassViewController:UIViewController{@IBOutletweakvartableView:UITableView!overridefuncviewDidLoad(){super.viewDidLoad()//Doanyadditionalsetupafterloadingtheview,typicallyfromanib.tableView.estimatedRowHeight=50tableView.

iOS Collection View : how to scroll a cell to the top of the screen

我想知道是否有办法将某个UICollectionViewCell滚动到View的顶部?我尝试了collectionView.scrollToItemAtIndexPath()方法,但不是将单元格滚动到View的顶部,而是将单元格滚动到View的中心。 最佳答案 您可以使用以下代码:#pragmamark-UICollectionViewDelegate-(void)collectionView:(UICollectionView*)collectionViewdidSelectItemAtIndexPath:(NSIndexPath

ios - "unable to dequeue a cell with identifier"当切换到编程转换而不是 segue 时

我有2个View,一个里面有一个按钮的主视图,一个表格View。TableView单元格具有标识符“ResultsTableViewCell”。我的目标是当我按下主视图上的按钮时,我会转换到表格View当我使用Storyboardsegue时,一切正常。但是,当我取出segue而不是为按钮分配一个Action以编程方式进行转换时,我得到了提到的错误。这是为什么?代码如下:ViewController.swift(这是我进行任何更改的唯一文件)classViewController:UIViewController{overridefuncviewDidLoad(){super.view

ios - swift 3 : Resizing UICollectionViewCell programmatically causes cells to overlap

我正在尝试创建一个UICollectionView,其中3个单元格彼此下方。这工作正常。当我触摸一个单元格时,这个单元格应该展开,其他单元格应该折叠到特定高度。也工作得很好。我无法解决的问题;当我点击一个单元格时,它会像我想要的那样展开;它与下面的重叠。下面的那个不会向下移动来为这个单元格的新高度腾出空间。我该如何解决这个问题?这是我到目前为止与UICollectionView和UICollectionViewCell相关的内容/***Tempory3items*/funccollectionView(_collectionView:UICollectionView,numberOfI

ios - swift : UITableViewCell separator for the first the cell only

我想显示不带分隔符的评论,如下图所示我尝试使用分隔符但它不起作用我只需要第一个单元格的分隔符。super.viewDidLoad()self.commentstableView.separatorColor=UIColor.clearColor()functableView(tableView:UITableView,cellForRowAtIndexPathindexPath:NSIndexPath)->UITableViewCell{//post'ssection==0ifindexPath.section==0{letcell=tableView.dequeueReusableC

json - 在 Swift 中从 JSON 解码 base64_encode 图像

我有一个包含一些图像的mysql数据库。我从一个php文件接收数据:php:$result[$key]['image']=based64_encode($resultArray[$key]['image']);现在有了Json文件,我得到了这样的东西:Json:{"image":"\/9j\/4Q\/+RXhpZgAATU0AKgAAAAgACgEPAAIAAAAGAAAAhgEQAAIAAAAKAAAAjAESAAMAAAABAAYAAAEaAAUAAAABAAAAlgEbAAUAAAABAAAAngEoAAMAAAABAAIAAE...我有我的swift项目,想将图像解码为UIIm

ios - 从自定义 Cell 中正确委托(delegate)按钮操作以删除 UITableView 中的行

仍然是一个Swift菜鸟,我一直在寻找一种正确的方法/最佳实践来管理我的UITableView(使用自定义UserCell)中的行删除基于使用委托(delegate)在UserCell中点击UIButton,这似乎是最简洁的方法。我按照这个例子:UITableViewCellButtonswithaction我有什么UserCell类protocolUserCellDelegate{funcdidPressButton(_tag:Int)}classUserCell:UITableViewCell{vardelegate:UserCellDelegate?letaddButton:UI

ios - 用户界面测试 : Slider fails to adjust when nested in Table View Cell

在Xcode9.0(9A235)上的UI测试中,当UISlider时,使用adjust(toNormalizedSliderPosition:)与UISlider交互根本不起作用嵌套在UITableViewCell中。我已经在许多不同的场景中进行了测试:-未嵌入UITableView的普通UISlider可与adjust方法一起正常工作。-与UITableView共存但不在TableViewCell中的UISlider继续与adjust配合使用-UITableView中的UISlider可以被唯一标识。-在UITableView中标识的UISlider可以响应像tap()这样的简单事件

ios - 如何在 Swift 4 中将 Encodable 或 Decodable 作为参数传递?

我正在学习JSONParsing。我按照教程进行操作,得到的是:guardleturl=URL(string:"http://localhost/test-api/public/api/register")else{return}varrequest=URLRequest(url:url)request.httpMethod="POST"letnewUser=User.init(name:self.collectionTF[0].text,email:self.collectionTF[1].text,password:self.collectionTF[2].text)do{letj