我正在使用React-Navigation并且我有一个StackNavigator,这是带有Stack + Tabs Navigator的app.js:
import React from 'react';
import { AppRegistry } from 'react-native';
import { StackNavigator, TabNavigator } from 'react-navigation';
import LoginScreen from './app/screens/LoginScreen';
import RegisterScreen from './app/screens/RegisterScreen';
import HomeScreen from './app/screens/HomeScreen';
import FriendsScreen from './app/screens/FriendsScreen';
const Stylelist = StackNavigator({
Login:{
screen: LoginScreen,
navigationOptions: ({navigation}) =>({
header: null,
}),
},
Register:{
screen: RegisterScreen,
navigationOptions: ({navigation}) =>({
header: null,
}),
},
Home:{
screen: HomeScreen,
navigationOptions: ({navigation}) =>({
title: "Home",
}),
},
});
const TabsNav = TabNavigator({
Home: {
screen: HomeScreen, …Run Code Online (Sandbox Code Playgroud) 我正在学习Swift,并在观看视频之前尝试自己编写Ryan Wenderlich的“ Bullseye”游戏。
我需要根据用户与目标数量的接近程度来给用户评分。我试图计算差异,然后检查范围并为用户提供分数,这是我对If-else所做的(对于切换用例无法做到):
private func calculateUserScore() -> Int {
let diff = abs(randomNumber - Int(bullsEyeSlider.value))
if diff == 0 {
return PointsAward.bullseye.rawValue
} else if diff < 10 {
return PointsAward.almostBullseye.rawValue
} else if diff < 30 {
return PointsAward.close.rawValue
}
return 0 // User is not getting points.
}
Run Code Online (Sandbox Code Playgroud)
有没有办法更优雅地使用Switch-Case?我不能仅仅diff == 0在切换情况下做例如xCode给我一个错误消息。
我正在尝试设置视图的背景颜色。我在这里设置了所有内容:
import React, { Component } from 'react';
import { View, StyleSheet, Text } from 'react-native';
export default class Login extends Component{
render(){
return(
<View style={styles.container}>
<Text>
Hello.
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container:{
flex: 1,
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'rgba(79, 81, 140, 1.0)',
}
});
Run Code Online (Sandbox Code Playgroud)
问题是视图保持白色。我尝试将文本添加到视图中,以查看它的背景颜色是否发生变化,并且确实发生了变化。如何将视图的背景颜色设置为我选择的颜色?我在网上搜索但找不到任何东西..
我正在构建一个 Ionic React(使用 Ionic 6 和 Capacitor)应用程序。我有两页,Home并且Profile。我想在主页和个人资料页面之间导航,它可以工作,但 iOS 模拟器上没有推送动画。
这是我的路由器(在 App.tsx 上):
<IonApp>
<IonRouterOutlet>
<IonReactRouter>
<Route exact path="/home" component={Home} />
<Route exact path="/profile" component={Profile} />
<Route exact path="/" render={() => <Redirect to="/home" />} />
</IonReactRouter>
</IonRouterOutlet>
</IonApp >
Run Code Online (Sandbox Code Playgroud)
当然,Home 和 Profile 作为IonPage根元素。
return (
<IonPage>
...
...
</IonPage>
);
Run Code Online (Sandbox Code Playgroud)
我使用 useIonRouter 钩子,如下所示:
const router = useIonRouter();
const displayProfile = () => {
router.push('/profile', 'forward', 'push');
};
Run Code Online (Sandbox Code Playgroud)
它确实会转到“个人资料”页面,但根本没有动画。除了在他们的网站上的基本示例之外,我找不到任何其他内容。
我正在使用table_calendar包在页面上显示日历。我希望用户能够从日历中选择日期,但是当点击日期时,日期focusedDay不会改变,因此它始终保持默认值focusedDay。
我尝试搜索文档,但我无法弄清楚出了什么问题,从文档看来它应该可以正常工作。
这就是我为 CalendarWidget 所做的:
TableCalendar(
focusedDay: _focusedDay,
firstDay: DateTime.now(),
lastDay: DateTime.utc(2030, 1, 1),
calendarFormat: CalendarFormat.month,
headerStyle: HeaderStyle(
formatButtonVisible: false,
titleCentered: true,
rightChevronIcon: Icon(
Icons.chevron_right,
size: 16,
color: Colors.grey,
),
leftChevronIcon: Icon(
Icons.chevron_left,
size: 16,
color: Colors.grey,
),
),
onDaySelected: (selectedDay, focusedDay) {
setState(() {
_selectedDay = selectedDay;
_focusedDay = focusedDay;
});
},
),
Run Code Online (Sandbox Code Playgroud)
这是一个有状态的小部件内部,我_focusdDay在该类中拥有一个变量,并对其进行更新。TableCalendar 当然位于build该类的函数内。
我不明白为什么设置视图的前导和尾随锚点不起作用,但是当我设置宽度时它确实起作用。我有一个UIStackView内部 a UIScrollView,这就是我设置的方式UIScrollView:
private func setupScrollView() {
addSubview(scrollView)
NSLayoutConstraint.activate([
scrollView.leadingAnchor.constraint(equalTo: self.leadingAnchor),
scrollView.trailingAnchor.constraint(equalTo: self.trailingAnchor),
scrollView.topAnchor.constraint(equalTo: backButton.bottomAnchor),
scrollView.bottomAnchor.constraint(equalTo: self.safeAreaLayoutGuide.bottomAnchor),
])
}
Run Code Online (Sandbox Code Playgroud)
这就是我设置的方式UIStackView:
private func setupTextfieldsStack() {
scrollView.addSubview(textfieldsStack)
let height = UIScreen.main.bounds.height * 0.35
NSLayoutConstraint.activate([
textfieldsStack.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor, constant: 16),
textfieldsStack.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor, constant: -16),
textfieldsStack.topAnchor.constraint(equalTo: scrollView.topAnchor, constant: 8),
textfieldsStack.heightAnchor.constraint(equalToConstant: height)
])
}
Run Code Online (Sandbox Code Playgroud)
由于某种原因,UIStackViewonly 占据了大约一半的屏幕,但是,当更改scrollView.leading为self.leading和 fortrailing时,这确实有效,并且UIStackView被拉伸以适应屏幕的几乎整个宽度。将宽度设置为 UIScreen 边界的 0.95 也可以。
所以,我的问题是,为什么当我使用self它时它可以工作但scrollView不起作用?我setupScrollView之前确实调用过setupTextfieldsStack …
我正在尝试使用Firebase创建一个数据库(json).我搜索了文档和网络,但找不到明确的方法开始.我想拥有一个用户数据库.每个用户(表示为UID)应该有一个昵称和一个朋友列表.
我尝试制作一个如下所示的.json文件:
{
users:{
}
}
Run Code Online (Sandbox Code Playgroud)
并将其添加到Firebase控制台以开始,但它不起作用.我该怎么做?
数据库应如下所示:
{
users:{
UID:{
nickname: hello
friends: UID2
}
UID2:{
nickname: world
friends: UID
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道我是否做得对,所以我非常感谢你们在这个问题上能给我的任何帮助.提前致谢!
我正在尝试更改我的活动标签标题颜色,尝试使用tabBarOptions,但是它不起作用,我在做什么错?这是我的代码:
Home:{
screen: TabNavigator({
Home: {
screen: HomeScreen,
navigationOptions: ({ navigation }) => ({
title: 'Home',
tabBarIcon: ({ tintColor, focused }) => (
<Ionicons
name={focused ? 'ios-home' : 'ios-home-outline'}
size={26}
style={{ color: focused ? `${tabBarColor}` : tintColor}}
/>
),
header: null,
}),
},
Profile: {
screen: ProfileScreen,
navigationOptions: ({ navigation }) => ({
title: 'Profile',
tabBarIcon: ({ tintColor, focused }) => (
<Ionicons
name={focused ? 'ios-people' : 'ios-people-outline'}
size={26}
style={{ color: focused ? `${tabBarColor}` : tintColor }}
/>
),
header: …Run Code Online (Sandbox Code Playgroud) 我从没有导航栏的屏幕移动到有导航栏的屏幕。转到导航栏屏幕时,该栏不包含在任何安全区域约束中,并且与 iPhone X 上的状态栏重叠。我寻找了一个解决方案,但没有任何效果。如何使导航栏符合 iPhone X 上的安全区域指南,使其不会重叠?此外,它的高度似乎太短了,但我想这可以通过约束来解决。
提前致谢!
应用委托:
var window: UIWindow?
var navigationController: UINavigationController?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.main.bounds)
if let window = window{
let mainVC = ViewController()
navigationController = UINavigationController(rootViewController: mainVC)
window.rootViewController = navigationController
window.makeKeyAndVisible()
}
return true
}
Run Code Online (Sandbox Code Playgroud)
这是我用来从 ViewController 移动到 AboutViewController 的方法:
@objc private func infoButtonTap(){
let aboutVC = AboutViewController()
self.navigationController?.pushViewController(aboutVC, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
编辑:这是它的外观:https : //imgur.com/syuQaUn …
我希望在未选择选项卡时将颜色设置为默认的灰色,而在选择选项卡时将其设置为我的tabBarColor颜色。我在标签栏中找不到更改标题颜色的方法。
我怎样才能做到这一点?
这是我的代码:
Home:{
screen: TabNavigator({
Home: {
screen: HomeScreen,
navigationOptions: ({ navigation }) => ({
title: 'Home',
tabBarIcon: ({ tintColor, focused }) => (
<Ionicons
name={focused ? 'ios-home' : 'ios-home-outline'}
size={26}
style={{ color: focused ? `${tabBarColor}` : tintColor}}
/>
),
//headerStyle: {backgroundColor: "#553A91"},
//headerTitleStyle: {color: "#FFFFFF"},
header: null,
}),
},
Profile: {
screen: ProfileScreen,
navigationOptions: ({ navigation }) => ({
title: 'Profile',
tabBarIcon: ({ tintColor, focused }) => (
<Ionicons
name={focused ? 'ios-people' : 'ios-people-outline'}
size={26}
style={{ …Run Code Online (Sandbox Code Playgroud) 我正在将一个整数数组保存到 PostgreSQL 表中,并且在尝试检索它时,我总是得到 []uint8 而不是 []int。我尝试使用 []integer、[]bigint、[]smallint。没有任何效果。该数组最多表示四项,每一项在 1-100 之间,没有浮点数。
我正在使用 Go,并且我有一个 []int 对象,这是字段:
Quantity []int `json:"quantity" db:"quantity"`
Run Code Online (Sandbox Code Playgroud)
我正在尝试修复它,但找不到让 PostgreSQL 返回 []int 的方法。
所有其他表字段都很好用。该Quantity字段的类型integer[]
这是插入查询:
"INSERT INTO products (product_id, name, manufacturer, image_url, quantity, amount, notes, store_id, store_name, owner_id) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)", newProduct.UID, newProduct.Name, newProduct.Manufacturer, newProduct.Image, pq.Array(newProduct.Quantity), newProduct.Amount, newProduct.Notes, newProduct.StoreID, newProduct.StoreName, newProduct.OwnerID);
Run Code Online (Sandbox Code Playgroud)
这就是我尝试获取数据的方式。
err := rows.Scan(&temp.ID, &temp.UID, &temp.Name, &temp.Manufacturer,
&temp.Image, &temp.Amount, &temp.Notes,
&temp.StoreID, &temp.OwnerID, &temp.StoreName, &temp.Quantity)
Run Code Online (Sandbox Code Playgroud)
问题仅在于数量。如果我更改temp object为[]uint8 …
在 iOS 14 出现之前,我有一个应用程序。我停止使用 Swift 几个月了,现在,模拟器正在运行 iOS 14,从那时起,我遇到了一个问题,我在 tableView 单元格中的 UIControl 没有注册点击。
这是我的 TableView(简单,没有自定义或任何东西):
private let tableView: UITableView = {
let table = UITableView(frame: .zero, style: .plain)
table.translatesAutoresizingMaskIntoConstraints = false
table.backgroundColor = .white
table.separatorInset.right = table.separatorInset.left
return table
}()
Run Code Online (Sandbox Code Playgroud)
这是我尝试设置点击手势的方式:
extension TodoListVC: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: todoCellIdentifier, for: indexPath) as! TodoCell
let todo = todoListViewModel.todos[indexPath.row]
cell.model = todo
cell.selectionStyle = .none
let checkBox = cell.checkbox
checkBox.index = …Run Code Online (Sandbox Code Playgroud) react-native ×4
swift ×3
ios ×2
firebase ×1
flutter ×1
go ×1
json ×1
nosql ×1
postgresql ×1
pq ×1
reactjs ×1
tabnavigator ×1