小编use*_*242的帖子

滚动时如何防止tableview节头粘住?

我有一个包含许多部分的表格视图。我正在使用一个实际的 tableview 单元格,我将其出列用作自定义节标题。我遇到的问题是当我将部分标题“粘”到表格顶部时,直到出现下一部分。

我怎样才能防止这种情况发生并让它像往常一样向上滚动?

这是我的代码

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    if section == 3 {
        let cell = tableView.dequeueReusableCell(withIdentifier: "headerCell") as! HeaderTableViewCell
        return cell
    }
    return UIView()
}
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift

9
推荐指数
2
解决办法
8050
查看次数

使用迦太基时要做什么?

这是我第一次使用迦太基!我正在使用一个名为" https://github.com/LeoNatan/LNPopupController " 的库,我得到它来处理我的项目.问题是我想提交这些更改但是当我这样做时,我得到一个弹出窗口,说某个文件大于10MB!

问题是,在使用迦太基时,你认为提交和不提交是什么?

这样的文件的图片:

在此输入图像描述

在源树上:

在此输入图像描述

git carthage

8
推荐指数
1
解决办法
2622
查看次数

实例成员不能用于嵌套类型的实例?

我在下面有以下代码,Xcode 不断给我一个错误,我不明白如何解决。

class ViewController: UIViewController {
    private var manager: Manager?

    enum Link {
        case faq
        case tos

        var url: String {
            switch self {
            case .faq:
                return "www.google.com"
            case .tos:
                return manager!.isFreeUser ? "www.google.com" : "www.duckduckgo.com"
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

错误是:

“ViewController”类型的实例成员“manager”不能用于嵌套类型“ViewController.Link”的实例

enums uiviewcontroller ios swift

6
推荐指数
2
解决办法
5265
查看次数

如何查找和取消订阅Firebase上的主题 - iOS?

我在iOS上使用Firebase并且正在尝试实施主题.我知道如何订阅和取消订阅:

Messaging.messaging().subscribe(toTopic: "myTopic")

Messaging.messaging().unsubscribe(fromTopic: "myTopic")
Run Code Online (Sandbox Code Playgroud)

我的问题是,我怎么知道我订阅了哪些主题?如何取消订阅我订阅的所有主题?如何从Firebase访问所有主题?

ios firebase swift firebase-cloud-messaging

5
推荐指数
1
解决办法
1957
查看次数

如何修复 UILabel 文本间距?

此代码在 iOS 12 及更低版本上运行良好,并且在运行 iOS 13 时会出现问题。目标是将行高间距删除为 0,以便我的标签在文本之间减少空间量。我在集合视图单元格中有两个标签,当我将单元格从屏幕上滚动然后向下滚动时,标签文本现在被“切断”了。这不是我在以前版本的 iOS 中提到的情况。任何解决此问题的帮助都将是惊人的。提前致谢。

这是我的代码:

extension: UILabel {

        func addLineSpacing(spacing: CGFloat) {
        guard let text = text else { return }

        let originalText = NSMutableAttributedString(string: text)
        let style = NSMutableParagraphStyle()
        let lineHeight = font.pointSize - font.ascender + font.capHeight
        let offset = font.capHeight - font.ascender
        let range = NSRange(location: 0, length: text.count)

        style.maximumLineHeight = lineHeight
        style.minimumLineHeight = lineHeight
        style.alignment = .center

        originalText.addAttribute(.paragraphStyle, value: style, range: range)
        originalText.addAttribute(.baselineOffset, value: offset, range: range)

        attributedText = originalText
    } …
Run Code Online (Sandbox Code Playgroud)

uilabel ios uicollectionview uicollectionviewcell swift

5
推荐指数
1
解决办法
360
查看次数

NSNotification被解雇多次?

我正在为测试项目创建一个示例播放器.我创建了一个NSNotification来调用一个函数来播放数组中的下一个音轨.问题是通知连续8次调用此函数?我不知道为什么会这样.这是我的代码,谢谢你的帮助!

let player = AVPlayer()

var urlPlayerItems = [String]()

var currentTrack: Int = 0



    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)

        // Checks to see if player reached end
        NotificationCenter.default.addObserver(self,
                                                    selector: #selector(PlayerViewController.autoplayNextTrack(notification:)),
                                                    name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
                                                    object: player.currentItem)

}

    func playTrack() {

        if urlPlayerItems.count > 0 {
            let newMovieURL = URL(string: urlPlayerItems[currentTrack])!
            asset = AVURLAsset(url: newMovieURL, options: nil)

            player.play()
        }
    }



    func autoplayNextTrack(notefication: NSNotification) {
        if (currentTrack + 1) >= urlPlayerItems.count {
            currentTrack = 0
        } else {
            currentTrack += 1
        } …
Run Code Online (Sandbox Code Playgroud)

iphone observers nsnotificationcenter ios swift

4
推荐指数
1
解决办法
777
查看次数

如何更改集合视图单元格大小并添加填充?

我试图让我的 collectionView 单元格看起来像下面的图片,但没能做到。我尝试使用 collectionViewLayout 但无法获得正确的大小和正确的填充。我怎么能做到这一点?

这是我的代码

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
            let frameSize = collectionView.frame.size
            return CGSize(width: frameSize.width, height: frameSize.height / 2)

    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        return UIEdgeInsets(top: 0, left: 27, bottom: 0, right: 27)
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我想要实现的目标的图片。谢谢

在此处输入图片说明

uiviewcontroller ios uicollectionview uicollectionviewcell swift

4
推荐指数
1
解决办法
2766
查看次数

如何在 UISearchController 中使用自定义视图控制器来获取结果?

我目前正在尝试为应用程序实现搜索功能。目标是在不同的视图控制器中显示搜索结果。我的意思确切地说是这样的:

UISearchController(searchResultsController: myCustomViewControllerHere)

我在教程中找到的所有答案都使用当前视图控制器和数据作为显示结果的视图控制器,如下所示:

UISearchController(searchResultsController: nil)

有人可以帮忙解决如何做到这一点吗?我链接了一个教程,它显示了同一 VC 上的结果

教程链接

iphone search ios swift uisearchcontroller

3
推荐指数
1
解决办法
3298
查看次数

如何为某些视图控制器锁定iPhone的方向 - Swift?

我有2个视图控制器,VC1和VC2.

VC1目前以模态方式呈现VC2.

VC1唯一的方向应该是纵向,但VC2可以具有所有方向.

问题是当我在VC2中并且我旋转到横向模式然后解雇时,VC1也处于横向模式!那应该永远不会发生!

注意:没有导航控制器或UITabbarcontroller

我正在添加我的代码.

Appdelagate:

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    if let rootViewController = self.topViewControllerWithRootViewController(rootViewController: window?.rootViewController) {
        if (rootViewController.responds(to: Selector(("canRotate")))) {
            // Unlock landscape view orientations for this view controller
            return .allButUpsideDown
        }
    }

    // Only allow portrait (standard behaviour)
    return .portrait;
}

private func topViewControllerWithRootViewController(rootViewController: UIViewController!) -> UIViewController? {
    if (rootViewController == nil) { return nil }
    if (rootViewController.isKind(of: (UITabBarController).self)) {
        return topViewControllerWithRootViewController(rootViewController: (rootViewController as! UITabBarController).selectedViewController)
    } else if (rootViewController.isKind(of:(UINavigationController).self)) …
Run Code Online (Sandbox Code Playgroud)

iphone model-view-controller screen-orientation ios swift

1
推荐指数
1
解决办法
3705
查看次数

隐藏导航栏时如何启用滑动手势?

我一直试图解决这个问题很长一段时间,但无法弄清楚。我有当前的设置:

在此处输入图片说明

在每个视图控制器中,我都隐藏了导航栏,如下所示:

        self.navigationController?.setNavigationBarHidden(true, animated: true)
Run Code Online (Sandbox Code Playgroud)

问题是我在隐藏导航栏的视图控制器上松开了滑动手势。我需要启用动画并且不能使用:

    self.navigationController?.navigationBar.isHidden = true
    self.navigationController?.isNavigationBarHidden = true 
Run Code Online (Sandbox Code Playgroud)

任何帮助都会很棒,因为我相信很多人都遇到过这个问题。谢谢!

uinavigationbar uinavigationcontroller uigesturerecognizer ios swift

1
推荐指数
1
解决办法
2222
查看次数

如何打印星期几的名称?

我试图打印出星期几的名称,即星期一,星期二,星期三.我目前有这样的代码就是这样做的.我想知道是否有办法摆脱我的switch语句并使其更好.谢谢!

 func getDayOfWeek(_ today: String) -> String? {
    let formatter  = DateFormatter()
    formatter.dateFormat = "yyyy-MM-dd"
    guard let todayDate = formatter.date(from: today) else { return nil }
    let myCalendar = Calendar(identifier: .gregorian)
    let weekDay = myCalendar.component(.weekday, from: todayDate)

    switch weekDay {
    case 1:
        return "Sunday"
    case 2:
        return "Monday"
    case 3:
        return "Tuesday"
    case 4:
        return "Wednesday"
    case 5:
        return "Thursday"
    case 6:
        return "Friday"
    case 7:
        return "Saturday"
    default:
        return ""
    }
}



getDayOfWeek("2018-3-5")
Run Code Online (Sandbox Code Playgroud)

打印出"星期一"

-1
推荐指数
1
解决办法
420
查看次数