我希望以编程方式向我的 UICollectionView 添加一个标签,并使用 viewForSupplementaryElementOfKind 和 referenceSizeForHeaderInSection 来设置它,但是由于某种原因,当我设置我的视图时,它仍然将它放在我的 CollectionView 的第一行中,而不是创建的标题。正如您在此屏幕截图中看到的,“今天”在第一个单元格中,而不是我为其创建的标题
class TvController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
private let cellId = "cellId"
private let headerId = "headerId"
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "TV"
navigationController?.navigationBar.isTranslucent = false
collectionView?.backgroundColor = .white
collectionView?.register(TvCell.self, forCellWithReuseIdentifier: cellId)
collectionView?.register(Header.self, forCellWithReuseIdentifier: headerId)
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath)
return cell …Run Code Online (Sandbox Code Playgroud) 我在尝试连接到本地 docker postgres 数据库时遇到问题。我在端口 5434 上启动了一个新的 postgres db 容器,我可以确认它正在成功运行。我在下面添加了 docker ps 命令响应。由于某种原因,当尝试在 DbBeaver 上连接到新的 5434 端口时,我只是收到以下错误 EOFException。我还附上了下面的图片。
不太明白发生了什么,因为我确信我输入了正确的身份验证详细信息,并且我在其他端口上尝试了多次,但只有到 5432 的连接有效。有人知道如何让另一个端口工作吗?
我正在努力理解如何最好地组织我的代码以在 React 中设置初始 useState(),同时使用 GraphQL 和 Apollo 引入数据。这是我的代码。如您所见,我想查看“数据”的一部分来设置初始状态,但是当我将 setSTate 移到加载和错误行下方时,出现以下错误:
React Hook "useState" 被有条件地调用。在每个组件渲染中,必须以完全相同的顺序调用 React Hooks。您是否在提前返回后不小心调用了 React Hook?反应钩子/钩子规则
我应该如何更好地组织这个?我是否必须使用 Apollo 的状态管理库,因为我更喜欢使用 React useState hooks。
const GET_LATEST_POSTS = gql`
query {
"graphql query is in here"
}
Run Code Online (Sandbox Code Playgroud)
...
const Slider = () => {
const { data, loading, error } = useQuery(GET_LATEST_POSTS)
if (loading) return 'Loading...'
if (error) return `Error! ${error.message}`
const [ currentMovie, setMovie ] = useState(data)
}
Run Code Online (Sandbox Code Playgroud) 只是寻找将以下数组转换为以下对象格式的最干净的方法。多谢
const item = [
{ address: '123 fake street' },
{ loan: 'no' },
{ property: 'no' }
]
const obj = {
address: '123 fake street',
loan: 'no',
property: 'no'
}
Run Code Online (Sandbox Code Playgroud) 我似乎无法修复此错误,该错误仅在我部署后才发生,这让我发疯。我已经尝试了所有其他堆栈溢出建议中的所有内容,但没有成功。我在本地没有收到任何错误,但是当我部署到 Heroku 时,我收到错误“错误:“line”不是已注册的控制器。” 有任何想法吗?
import React, { useState } from 'react';
import {
Chart as ChartJS,
CategoryScale,
LinearScale,
BarElement,
Title,
Tooltip,
Legend,
PointElement,
LineElement,
} from 'chart.js';
ChartJS.register(
CategoryScale,
LinearScale,
BarElement,
PointElement,
LineElement,
Title,
Tooltip,
Legend,
);
import { Chart } from 'react-chartjs-2';
const staticData = [
{
type: 'line',
label: 'Macleay Island Avg',
backgroundColor: '#38A169',
borderColor: '#38A169',
order: 1
},
{
type: 'bar',
label: 'Macleay Island Total',
backgroundColor: '#C6F6D5',
order: 3
},
{
type: 'line',
label: 'Russell Island Avg', …Run Code Online (Sandbox Code Playgroud) 我正在尝试以编程方式创建不同的视图控制器,其中第一个不应显示导航栏,但第二个应该显示。我似乎无法做任何事情来让第二个视图控制器显示导航栏。所有代码都可以正常编译,并且推动控制器的按钮可以工作,因为第二个屏幕会按预期变为绿色。
这是 AppDelegate:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
let layout = UICollectionViewFlowLayout()
let startupScreenController = StartupScreenController(collectionViewLayout: layout)
window?.rootViewController = UINavigationController(rootViewController: startupScreenController)
application.statusBarStyle = .lightContent
return true
}
Run Code Online (Sandbox Code Playgroud)
这是第一个视图控制器:
func skipButtonPressed() {
let layout = UICollectionViewFlowLayout()
let secondViewController = SecondViewController(collectionViewLayout: layout)
self.navigationController?.pushViewController(secondViewController, animated: true)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Hide …Run Code Online (Sandbox Code Playgroud) 我知道这看起来很基本,但我似乎找不到在 Nest.js 猫鼬模式中设置 _id 字段的正确方法。我附上了一张图片,只是想知道设置此属性的最佳方法是什么?我收到以下错误
“SchemaType”仅指类型,但在此处用作命名空间。ts(2702)
我有以下代码:
const [answerObject, setAnswerObject] = useState({})
const answerItem = {"question_" + survey.id, selectedAnswer}
setAnswerObject(answerObject + answerItem)
Run Code Online (Sandbox Code Playgroud)
我正在尝试得到这个结果:
answers = {
question_1: 'text from answer 1',
question_2: 'text from answer 2',
question_3: 'text from answer 3',
}
Run Code Online (Sandbox Code Playgroud)
但是我在插值时遇到了麻烦。我尝试了很多不同的方法但没有运气。任何正确格式化它的帮助或建议都会很棒。