小编Dav*_*tin的帖子

使用 Expo Router 传递对象

我需要使用将对象从一个屏幕传递到另一个屏幕expo-router

我有一个显示包含项目的 FlatList 的屏幕和一个显示有关该项目的更多信息的详细信息屏幕。附加信息位于项目对象内,因此不需要再次调用 API。

项目模型如下:

{
  id: "123",
  title: "Some Title",
  imageURL: "https://...",
  ...other: "some other data"
}
Run Code Online (Sandbox Code Playgroud)

使用 expo-router 我相信我需要提供 URL 参数,但是,对于包含图像 URL 的数据,这是不切实际的。

如何只传递不带 URL 参数的对象

目前我在函数中获取该项目如下;

const getDetails = (item) => {
    router.push({ pathname: `/details/${item.id}`, params: { item } });
};
Run Code Online (Sandbox Code Playgroud)

如何在第二个屏幕中显示此内容?

react-native expo expo-router

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

React Native TextInput 错误:执行输入操作需要有效的 sessionID

我有一个 React Native 项目,使用 Expo 管理的工作流程和 Prebuild。

我只是渲染一个 TextInput 组件,但收到此错误:

[RemoteTextInput] -[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] 执行输入操作需要有效的 sessionID

由于此错误,我的状态无法更新其值。我不知道这意味着什么。

包.json

"expo": "~49.0.15",
"react": "18.2.0",
"react-native": "0.72.6",
Run Code Online (Sandbox Code Playgroud)

在 TextInput 中输入文本后:

[CoreGraphics] 错误:此应用程序或其使用的库已将无效的数值(NaN 或非数字)传递给 CoreGraphics API,并且该值将被忽略。请解决这个问题。[CoreGraphics] 如果您想查看回溯,请设置 CG_NUMERICS_SHOW_BACKTRACE 环境变量。

<TextInput
  style={[styles.input, { backgroundColor: lightGray }]}
  autoCapitalize="none"
  autoComplete="email"
  keyboardType="email-address"
  placeholder="Email"
  onChangeText={(text) => setEmail(text)}
  value={email}
/>
<TextInput
  style={[styles.input, { backgroundColor: lightGray }]}
  autoCapitalize="none"
  placeholder="Password"
  secureTextEntry={true}
  onChangeText={(text) => setPassword(text)}
  value={password}
/>
Run Code Online (Sandbox Code Playgroud)

更新

然后我在新的npx create-expo-app跑步中尝试了这个并得到了相同的结果。npx expo prebuildnpx expo run:ios

react-native expo

9
推荐指数
0
解决办法
1877
查看次数

UIEdgeInsets 不适用于 TabBar 中的系统图像

我正在使用 XCode 系统图像(SF 符号)作为UITabBarItem图像。我想删除UITabBarItem我已经完成的标题。但也要UITabBarItem稍微向下移动图像。

过去,当我不使用系统映像时,使用UIEdgeInsets. 但是,这似乎对系统映像没有影响。

代码:

let imageConfiguration = UIImage.SymbolConfiguration(weight: .regular)
    let imageInsets = UIEdgeInsets(top: 8, left: 0, bottom: -8, right: 0)

lazy var activityTabBarItem: UITabBarItem = {
        let image = UIImage(systemName: "stopwatch")?.applyingSymbolConfiguration(imageConfiguration)
        let tabBarItem = UITabBarItem(title: nil,
                                      image: image,
                                      selectedImage: image)
        tabBarItem.imageInsets = imageInsets
        return tabBarItem
    }()
Run Code Online (Sandbox Code Playgroud)

有解决方法吗?

xcode uitabbaritem uiedgeinsets swift sf-symbols

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

根据位置半径过滤Firebase数据库

我有以下Firebase数据库结构,

"-KSupX7CppMD1zbqIy0y" : {
  "addedByUser" : "zQpb7o18VzYsSoTQtT9DNhOqTUn2",
  "content" : "Post 1",
  "cost" : "20",
  "duration" : "Weekly",
  "latitude" : "40.7594479995956",
  "longitude" : "-73.9838934062393",
  "timestamp" : "Fri 30 Sep"
},
"-KSuphuqO6a0lnrJYUkt" : {
  "addedByUser" : "zQpb7o18VzYsSoTQtT9DNhOqTUn2",
  "content" : "Post 2",
  "cost" : "10",
  "duration" : "Daily",
  "latitude" : "40.7594329996462",
  "longitude" : "-73.9846261181847",
  "timestamp" : "Fri 30 Sep"
}
Run Code Online (Sandbox Code Playgroud)

我需要在一定的距离参数(小于50米,100米,150米和200米)内过滤帖子.我可以从"经度"和"纬度"获得坐标,但我很难过滤帖子.任何帮助将不胜感激.

提前谢谢了.新手到Firebase和Swift.

location filter firebase swift firebase-realtime-database

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

使用SearchController推送ViewController,在搜索栏下显示黑色矩形

当我将另一个控制器推到堆栈上时(当有一个搜索控制器时)我在搜索栏下面有一个黑色块.我在下面的所有部分都将背景颜色设置为白色;

  • 搜索控制器
  • 搜索栏
  • 目前的VC
  • 下一个VC

回到堆栈时也会出现.

搜索控制器

func setUpSearchController() {
        searchController.delegate = self
        searchController.view.backgroundColor = .white
        searchController.searchBar.backgroundColor = .white
        searchController = UISearchController(searchResultsController: nil)
        searchController.hidesNavigationBarDuringPresentation = true
        searchController.dimsBackgroundDuringPresentation = true
        searchController.searchBar.sizeToFit()
        searchController.searchBar.backgroundColor = .white
        searchController.searchBar.barTintColor = .white
        searchController.searchBar.placeholder = "Search"
        searchController.searchBar.searchBarStyle = .minimal
        searchController.searchBar.tintColor = Colours.brandGreen
        definesPresentationContext = true
        if #available(iOS 11.0, *) {
            navigationItem.searchController = searchController
            navigationItem.hidesSearchBarWhenScrolling = true
        } else {
            messagesTableView.tableHeaderView = searchController.searchBar
        }
    }
Run Code Online (Sandbox Code Playgroud)

选择了Cell

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let chatController = ChatController() …
Run Code Online (Sandbox Code Playgroud)

uinavigationcontroller uisearchbar swift uisearchcontroller

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

使用Google Places API时发生错误“获取输出帧失败,状态8196”

我有一个searchController从Google Places API获取数据。我正在使用UITableView填充单元格,但是未填充它们(我假设由于上述错误)

  • 我已经设置了所有代表
  • TableView正在重新加载数据
  • 该请求将按预期方式在控制台中打印

根据我在S / OF上阅读的内容,这可能与单元格的注册有关-请参见以下代码

表格检视

func configureTableView() {
        tableView.delegate = self
        tableView.dataSource = self
        view.addSubview(tableView)
        tableView.anchor(top: view.topAnchor, left: view.leftAnchor, bottom: view.bottomAnchor, right: view.rightAnchor,
                         paddingTop: 0, paddingLeft: 0, paddingBottom: 0, paddingRight: 0,
                         width: 0, height: 0)
        tableView.tableFooterView = UIView()
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: recentSearchesCellIdentifier)
        tableView.register(ResultsCell.self, forCellReuseIdentifier: searchResultsCellIdentifier)
        tableView.keyboardDismissMode = .interactive
        tableView.backgroundColor = UIColor(red: 242/255, green: 242/255, blue: 243/255, alpha: 1)
    }
Run Code Online (Sandbox Code Playgroud)

CellForItemAtIndexPath

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let recentSearchesCell = tableView.dequeueReusableCell(withIdentifier: recentSearchesCellIdentifier, for: …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift google-places-autocomplete

6
推荐指数
0
解决办法
2489
查看次数

Pod Init 没有创建 xcworkspace?

我启动了一台新 Mac,运行 sudo gem install cocoapods。完成 pod 初始化。Pod 文件已创建,但没有 .xcworkspace 文件

使用 Xcode 9.3

任何帮助表示赞赏。

尝试过:卸载 cocoapods 并重新安装,但没有运气。

xcode cocoapods

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

具有动态标签宽度的堆栈视图分布

然而,我有一个UIStackView,第一个视图subViews是 aUILabel并且它没有相应地调整它的大小。

我的代码如下;

private let stackView: UIStackView = {
    let view = UIStackView()
    view.translatesAutoresizingMaskIntoConstraints = false
    view.axis = .horizontal
    view.distribution = .fillProportionally
    view.alignment = .trailing
    view.spacing = 8
    return view
}()
Run Code Online (Sandbox Code Playgroud)

当然,我添加了以下内容subViewsinit

    stackView.addArrangedSubview(currentBidLabel)
    stackView.addArrangedSubview(seperator)
    stackView.addArrangedSubview(adCreatedAtLabel)
    stackView.addArrangedSubview(moreButton)
Run Code Online (Sandbox Code Playgroud)

我目前的结果如下图所示;

插图

我正在寻找的结果如下;

  1. 红色 = 动态标签宽度(与蓝色相同)
  2. 绿色 = 固定宽度
  3. 蓝色 = 填充剩余空间
  4. 青色 = 固定宽度

ios stackview nslayoutconstraint swift

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

UIImagePickerController导航栏色调颜色不适用于iOS 13

我正在介绍一个模态控制器,它是一个UIImagePickerController。

我正在尝试更改UIImagePickerController导航栏的颜色。

在iOS13之前,此方法运行良好;

imagePickerController.navigationBar.tintColor = .red
Run Code Online (Sandbox Code Playgroud)

我也尝试过;

imagePickerController.navigationController?.navigationBar.tintColor = .red
Run Code Online (Sandbox Code Playgroud)

但仍然没有喜悦。

一如既往的任何帮助深表感谢!

uinavigationbar uiimagepickercontroller swift ios13

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

更改 UIAlertViewController 色调颜色

我正在为我的 swift 应用程序使用谷歌登录。当用户点击登录 API 时,会给出这个UIAlert. 有什么办法可以改变它的色调吗?即“取消”和“继续”?

用户界面警报视图

我什至尝试使用下面的 AppDelegate 代码全局更改它;

UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = Color.brandPurple
Run Code Online (Sandbox Code Playgroud)

这没有效果。

uiview uialertview ios swift uialertcontroller

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

使用注释坐标删除注释

我正在使用Firebase将注释添加到mapView。这可以通过以下步骤完成:

 func getMarkers() {

    dbRef.observe(.value, with: { (snapshot) in

        for buildings in snapshot.children {

            let buildingsObject = Buildings (snapshot: buildings as! FIRDataSnapshot)

            let latDouble = Double(buildingsObject.latitude!)
            let lonDouble = Double(buildingsObject.longitude!)

            self.telephoneNumber = buildingsObject.number

            let annotation = myAnnotationView.init(title: buildingsObject.content!, coordinate: CLLocationCoordinate2D.init(latitude: latDouble!, longitude: lonDouble!), duration: buildingsObject.duration!, cost: buildingsObject.cost!, info: "", timestamp: buildingsObject.timestamp, contactNumber: buildingsObject.number!, addedBy: buildingsObject.addedByUser!)

            self.mapView.addAnnotation(annotation)

            print (snapshot)

        }})}
Run Code Online (Sandbox Code Playgroud)

myAnnotationView是AnnotationView的自定义类。
向地图添加注释没有问题。问题在于,如果用户需要删除其注释,则需要将其从mapView中删除。我有一张桌子,上面有所有用户注释,如果他们愿意,他可以在其中删除。这将更新为Firebase控制台,并删除数据。但是,注释仍在地图上,仅当您重置应用程序时,注释才会更新。

我有一种方法来观察deleteChilds,它获得了正确的快照,但我似乎无法引用需要删除的注释。

func removeMarkers() {

    dbRef.observe(.childRemoved, with: { (snapshot) in

                        print (snapshot)

    })}
Run Code Online (Sandbox Code Playgroud)

被吐出来的快照在这里:

Snap (-KTo3kdGGA_-rfUhHVnK) { //childByAutoID
    addedByUser = …
Run Code Online (Sandbox Code Playgroud)

mapkit ios firebase swift firebase-realtime-database

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