小编Sha*_*aek的帖子

如何在cell.swift中获取indexPath.row

我有2个文件.

  • myTableViewController.swift
  • myTableCell.swift

我可以在myTabelCell.swift函数中获取indexPath.row吗?

这是myTableCell.swift

import UIKit
import Parse
import ActiveLabel

class myTableCell : UITableViewCell {

    //Button
    @IBOutlet weak var commentBtn: UIButton!
    @IBOutlet weak var likeBtn: UIButton!
    @IBOutlet weak var moreBtn: UIButton!


    override func awakeFromNib() {
        super.awakeFromNib()


    }

    @IBAction func likeBtnTapped(_ sender: AnyObject) {

        //declare title of button
        let title = sender.title(for: UIControlState())

        //I want get indexPath.row in here!

    }
Run Code Online (Sandbox Code Playgroud)

这是myTableViewController.swift

class myTableViewController: UITableViewController {

    //Default func
    override func viewDidLoad() {
        super.viewDidLoad()

        //automatic row height
        tableView.estimatedRowHeight = 450
        tableView.rowHeight = …
Run Code Online (Sandbox Code Playgroud)

uitableview nsindexpath swift

25
推荐指数
4
解决办法
5万
查看次数

如何通过自动布局设置集合视图的单元格大小

嗨,我正试图通过改变细胞大小auto layout.

我想用3乘3显示单元格.

第一个Cell的边距= 0

最后一个单元格的边距= 0

并且所有小区的空间都是1pt.像一个instagram.

在此输入图像描述

在此输入图像描述

我应该设置为Cell的尺寸吗?我希望通过Autolayout设置约束.

我也尝试使用代码设置单元格的大小.

这是我的代码:

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    return CGSizeMake(123, 123);
}

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
    return 1;
}

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat {
    return 1;
}
Run Code Online (Sandbox Code Playgroud)

但是......我认为它并不完全可以计算出细胞的大小.

如何根据屏幕尺寸设置单元格的大小?

我必须在单元格之间设置1pt的空间.

无论如何只能使用故事板设置?

如果没有,我如何设置代码?

谢谢.

uicollectionview uicollectionviewcell swift ios-autolayout

18
推荐指数
3
解决办法
4万
查看次数

Webpack 4 for SSR,如何解决此ReferenceError:窗口未定义?

我有3个webpack.config文件来启用Server-Sive-Rendering。

  • webpack.base.js
  • webpack.client.js
  • webpack.server.js

构建脚本

"scripts": {
        "dev": "npm-run-all --parallel dev:*",
        "dev:bundle": "nodemon --watch build --exec \"node build/bundle.js\"",
        "dev:server": "webpack --config webpack.server.js --watch",
        "dev:client": "webpack --config webpack.client.js --watch"
      }
Run Code Online (Sandbox Code Playgroud)

我正在努力在SSR上设置CSS。

当我尝试:

  • npm run dev:client->它没有错误!

  • npm运行dev:server->它没有错误!

但是,npm run dev:bundle我收到一条错误消息。

在此处输入图片说明

这是我的webpack设置

webpack.base.js

const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const devMode = process.env.NODE_ENV !== 'production';

module.exports = {
    module: {
        rules: [
            {
                test: /\.js?$/,
                loader: 'babel-loader',
                exclude: /node_modules/,
                options: {
                    presets: [
                        'react',
                        'stage-0',
                        ['env', { target: { browsers: ['last 2 versions'] }}]
                    ] …
Run Code Online (Sandbox Code Playgroud)

reactjs webpack server-side-rendering

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

如何在swift 3中使用addAttribute和NSRANGE

嗨,我想addAttribute在Swift3中使用.

我想要只设置粗体IDNAME.

这就是我想要的.

let boldUsername = NSMutableAttributedString(string: "IDNAME hi nice 2 meet you :D #HELLOW")


//            boldUsername.addAttribute(NSFontAttributeName, value: UIFont(name: "SFUIText-Bold", size: 14)!, range: (boldUsername.string as NSString).range(of: " "))

            boldUsername.addAttribute(NSFontAttributeName, value: UIFont(name: "SFUIText-Bold", size: 14)!, range: NSRange(location: 0, length: 5))
Run Code Online (Sandbox Code Playgroud)

我如何获得IDNAME的索引,即每次都不同?

- >有没有办法分割空间并获得索引?

nsattributedstring addattribute nsrange swift swift3

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

如何在TextField(SwiftUI)上添加底线

我曾经Rectangle()在TextField(SwiftUI)上添加底部边框

但是我想使用protocol TextFieldStyle诸如RoundedBorderTextFieldStyle之类的TextField Style的底线

如何在不使用Rectangle的情况下为TextField创建自定义样式?

https://developer.apple.com/documentation/swiftui/staticmember

在此处输入图片说明

struct ContentView : View {
    @State private var username = "Text Hellow"
    var body: some View {
        VStack() {
            TextField($username)
                .foregroundColor(Color.yellow)
            Rectangle()
                .frame(height: 1.0, alignment: .bottom)
                .relativeWidth(1)
                .foregroundColor(Color.red)

        }
        .padding()
    }

    func editChanged() {

    }
}

#if DEBUG
struct ContentView_Previews : PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
#endif
Run Code Online (Sandbox Code Playgroud)

textfield swift swiftui

3
推荐指数
5
解决办法
1221
查看次数

如何用代码注释画一条线?

在此处输入图片说明

嗨,我想使用注释分隔属性和函数。

如何在代码中注释以实现像绿线?

xcode swift

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

gatsby-remark-prismjs 不适用于 html

gatsby-remark-prismjs 不适用于我的设置。

我正在尝试突出显示 javascript 和 swift 等代码。

我的博客内容来自 wordpress.com

在此处输入图片说明

这是我的 gatsby.config.js

,
      {
        resolve: `gatsby-transformer-remark`,
        options: {
          plugins: [
            {
              resolve: `gatsby-remark-prismjs`,
              options: {
                // Class prefix for <pre> tags containing syntax highlighting;
                // defaults to 'language-' (eg <pre class="language-js">).
                // If your site loads Prism into the browser at runtime,
                // (eg for use with libraries like react-live),
                // you may use this to prevent Prism from re-processing syntax.
                // This is an uncommon use-case though;
                // If you're …
Run Code Online (Sandbox Code Playgroud)

graphql gatsby

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