因此,我试图创建一个函数,用户可以删除自己的评论/报告其他人。
我已经在帖子中完成了此操作,所以我假设我将使用相同的方法..它正在获取注释UID的所有者,并检查该用户是否为当前用户。如果是当前用户,那么我将设置警报控制器以显示“删除”,否则将是“报告”
这是正确运行的post函数的示例代码
func handleOptionsTapped(for cell: FollowingCell) {
guard let post = cell.post else { return }
// If post belongs to current user display delete action sheet.. else report
if post.ownerUid == Auth.auth().currentUser?.uid {
let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
alertController.addAction(UIAlertAction(title: "Delete Post", style: .destructive, handler: { (_) in
post.deletePost()
Run Code Online (Sandbox Code Playgroud)
也是中的帖子值 FollowingCell
var post: Post? {
didSet {
guard let ownerUid = post?.ownerUid else { return }
guard let imageUrl = post?.imageUrl else { return } …Run Code Online (Sandbox Code Playgroud) 我有点卡在这里。我的导航栏中嵌入了一个搜索栏作为我想要的标题。
然而接下来我想导航到集合视图中包含 UIsearchcontroller 的另一个视图控制器,当点击取消时,用户将返回到前一个视图。(与 Facebook 或 Instagram 使用搜索栏控制器非常相似)
无论如何,我可以使用搜索栏作为按钮导航到处理所有搜索功能的下一个视图控制器吗?
这就是我到目前为止的搜索栏。
func setUpNavBar() {
let searchBar = UISearchBar()
searchBar.sizeToFit()
searchBar.searchBarStyle = .minimal
searchBar.placeholder = "Search by username"
searchBar.tintColor = UIColor.lightGray
searchBar.barTintColor = UIColor.lightGray
navigationItem.titleView = searchBar
searchBar.isTranslucent = true
}
Run Code Online (Sandbox Code Playgroud)
编辑
只是添加到下面的答案中,如果有人遇到此问题并且您想要获得将搜索栏视为按钮的效果,请使用
func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool {
self.present(UINavigationController(rootViewController: SearchBarController()), animated: true, completion: nil)
searchBar.setShowsCancelButton(false, animated: true)
return false
}
Run Code Online (Sandbox Code Playgroud)
这样,当您单击搜索栏时,您不会获得显示搜索栏处于活动状态的效果(如果有意义的话)。当您点击搜索栏时,没有任何效果,它只是将您带到(真正的)搜索视图控制器,然后搜索栏处于活动状态,并且键盘上显示有取消按钮。我希望这是有道理的,如果有人想要一个示例,请访问 Instagram、FB 或 Pinterest,然后点击他们的搜索栏或搜索图标,您就会看到。
我有一个带有显示用户信息的部分标题的集合视图。标题可以包括来自用户的个人简介。如果 bio 很长,我在调整标题大小时会遇到问题。标签不会显示整个生物,因为标题保持在一个固定的高度。
我通过故事板创建了集合视图,但是我以编程方式添加了约束。
这是生物限制,我想通过将高度和线条设置为 0 就可以了,
addSubview(bioLabel)
bioLabel.anchor(top: editProfileButton.bottomAnchor, left: leftAnchor, bottom: nil, right: rightAnchor, paddingTop: 12, paddingLeft: 12, paddingBottom: 0, paddingRight: 12, width: 0, height: 0)
Run Code Online (Sandbox Code Playgroud)
我还认为我可以通过以下方式覆盖故事板
// Trying to override storyboard header height so the header can strech depending on the bio height
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
//TODO change height to be bounds.height of bioLabel?
return .init(width: view.frame.width, height: 300)
}
Run Code Online (Sandbox Code Playgroud)
但即使我尝试通过代码更改大小,它也会将故事板高度保持为 225(这是我想要的)