小编Ale*_*ith的帖子

滚动UITableView上的值更改

我有一个带有按钮的UITableView,根据用户是否"收藏"一个帖子来切换.一切都很好,除了滚动表格视图,按钮改变.这是我的代码:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    guard let feed = self.feed else {
        return 0
    }
    return feed.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    if feed!.count > 9 {
        if indexPath.row == feed!.count - 1 {
            self.loadMorePosts()
        }
    }

    if hasImageAtIndexPath(indexPath) {
        return imageCellAtIndexPath(indexPath)

    } else {
        return basicCellAtIndexPath(indexPath)
    }

}

func hasImageAtIndexPath(indexPath:NSIndexPath) -> Bool {
    let post = self.feed?[indexPath.row]

    if post?.image?.isEmpty == false {
        return true
    }

    return false
}

func …
Run Code Online (Sandbox Code Playgroud)

ios swift

11
推荐指数
2
解决办法
2614
查看次数

斯威夫特单身人士

我目前正在开发使用他们的移动购买sdk的Shopify应用程序,我正在尝试使用Swift中的Singleton来保存购物车.我有一个像这样设置的Singleton类:

class Singleton {

   static let sharedInstance = Singleton()

   init() {
     var cart = BUYCart()
     println(cart)
   }
}
Run Code Online (Sandbox Code Playgroud)

初始化后,它会在控制台中打印BUYCart.问题是我试图在控制器中访问保存的购物车,如下所示:

  println(Singleton.sharedInstance.cart.lineItems)
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

 Singleton does not have member named 'cart'
Run Code Online (Sandbox Code Playgroud)

singleton ios swift

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

在集合视图中更改每个第3个单元格的宽度

我想更改集合视图中每个第3个单元格的宽度.目前,我正在设置元素的宽度和高度,如下所示:

  func collectionView(collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    let width = UIScreen.mainScreen().bounds.size.width
    return CGSize(width: width / 2, height: width/2)
}
Run Code Online (Sandbox Code Playgroud)

如何选择集合视图中的每个第3个元素并使该元素全宽?在css中,它是元素:nth-​​child(3n),所以类似的东西.

uicollectionview swift

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

标签 统计

swift ×3

ios ×2

singleton ×1

uicollectionview ×1