小编Gur*_*ngh的帖子

SwiftUI NavigationView 删除空白

我有一个HomeView

NavigationView {
    ZStack {
        VStack {
             NavigationLink(destination: ProfileView()) {
                 if session.userInSession?.activated != 1 {
                     completionText(message: "Complete Your Profile")
                 } else {
                     completionText(message: "Edit Your Profile")
                 }
             }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的ProfileView没有包含在导航视图中,也没有栏标题:

VStack {
    ScrollView(showsIndicators: false) {
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

但我的ProfileView也可以从我的访问SettingView

NavigationView {
    VStack(alignment: .leading) {
        List {
            NavigationLink(destination: ProfileView()) {
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当我ProfileView从设置屏幕访问我的时,它显示正常。但是当我从我的访问它时,HomeView它会在顶部创建空白:

在此输入图像描述

当我通过“设置”时,效果很好:

在此输入图像描述

如何删除上面的空白?

swift swiftui swiftui-navigationlink swiftui-navigationview

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

无法解析模块`@expo/vector-icons`

我不确定为什么会收到此错误:

Unable to resolve module `@expo/vector-icons` from `...(directory path here)...` : Module does not exist in the module pack
Run Code Online (Sandbox Code Playgroud)

我尝试了其他论坛/网站上建议的以下内容:

  1. 清晰的守望者手表
  2. 删除 node_modules 文件夹
  3. 重置打包缓存

包.json

{
  "name": "app name",
  "version": "0.0.0",
  "description": "Hello Expo!",
  "author": null,
  "private": true,
  "main": "node_modules/expo/AppEntry.js",
  "dependencies": {
    "babel-plugin-module-resolver": "^2.5.0",
    "babel-preset-expo": "^4.0.0",
    "expo": "^21.0.0",
    "firebase": "^4.5.1",
    "geofire": "^4.1.2",
    "moment": "^2.19.1",
    "react": "16.0.0-alpha.12",
    "react-native": "https://github.com/expo/react-native/archive/sdk-21.0.2.tar.gz",
    "react-navigation": "^1.0.0-beta.13"
  }
}
Run Code Online (Sandbox Code Playgroud)

但仍然没有,仍然收到此错误

npm react-native expo

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

Postgres LIKE在Rails应用程序中

我有这样的Postgres LIKE声明:

@favorites.find_each do |profiles|
  @related_profiles = Profile.where('name LIKE ?', '%' + profiles.name + '%')
end
Run Code Online (Sandbox Code Playgroud)

我正在尝试做的是遍历favourites变量,并找到带有contain某些名称字符的所有配置文件。

例如,"jasson jackson"如果名称包含"jackson""jasson"

ruby postgresql ruby-on-rails ruby-on-rails-4 rails-activerecord

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

根据点击的按钮渲染三个不同的部分

所以我有这样的布局:

家用/ index.html.erb:

<div class="optionscontainer btn-group btn-group-justified">
   <%= link_to posts_path, class:"options btn btn-primary", remote: true do %>
      <i class="fa fa-book optionseach" aria-hidden="true"></i>All posts
   <% end %>
   <%= link_to stories_path, class:"options btn btn-primary", remote: true do %>
      <i class="fa fa-book optionseach" aria-hidden="true"></i>All stories
   <% end %>
</div>
   <div id="content" class="">
   </div>
Run Code Online (Sandbox Code Playgroud)

在posts_controller.rb中

我有:

def index
    @posts = Post.all
    respond_to do |format|
      format.html #looks for views/books/index.html.erb
      format.js   #looks for views/books/index.js.erb
    end
  end
Run Code Online (Sandbox Code Playgroud)

在stories_controller.rb中

我有:

def index
    @stories = Story.all
    respond_to do |format| …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails ruby-on-rails-4

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

在 rails 中与设计用户建立 has_one 关系

我是 Rails 的新手,并且很难由设计用户创建配置文件

这是 ProfileController:

class ProfilesController < ApplicationController

  before_action :set_profile, only: [:show, :edit, :update, :destroy]
  before_action :authenticate_user!

def index
 @profiles = Profile.all
end

def new
 @profile = current_user.build_profile
end

def create
@profile = current_user.build_profiles(profile_params)
redirect_to profiles_path
end

def show

end

def edit

end

def update
@profile.update(profile_params)
redirect_to(profiles_path(@profile))
end

def destroy
@profile.destroy
redirect_to profiles_path
end

private
def profile_params
params.require(:profile).permit(:university, :degree)
end

def set_profile
@profile = Profile.find(params[:id])
end

end
Run Code Online (Sandbox Code Playgroud)

当我运行 Rails 服务器时,我可以提交表单,但没有任何内容存储在模型“配置文件”中

这是数据应该出现的 index.html.erb:

<h2>profiles</h2>

<% @profiles.each do |profile| %>

  <%= …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails devise ruby-on-rails-4

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

无法找到类型为'application/javascript'的文件'jquery-ui/datepicker'

我已经在stackoverflow上尝试了多个答案,而且似乎没有工作,但无论如何这里是个问题.

我试着active-admin用我的Rails 5应用程序.

在我的宝石文件中,我有:

gem 'activeadmin', git: 'https://github.com/activeadmin/activeadmin'
gem 'inherited_resources', git: 'https://github.com/activeadmin/inherited_resources'
gem 'jquery-ui-rails'
Run Code Online (Sandbox Code Playgroud)

在我的application.js中,我有:

//= require jquery
//= require bootstrap-sprockets
//= require ckeditor/init
//= require jquery-ui
//= require jquery-ui/datepicker
//= require jquery_ujs
//= require turbolinks
//= require_tree .
Run Code Online (Sandbox Code Playgroud)

在我的application.scss中我有:

@import "jquery-ui";
@import "jquery-ui/datepicker";
Run Code Online (Sandbox Code Playgroud)

尽管遵循了所述的所有说明,但我收到了一个错误:

couldn't find file 'jquery-ui/datepicker' with type 'application/javascript
Run Code Online (Sandbox Code Playgroud)

并且错误似乎发生在这里:

//= require jquery-ui/datepicker
Run Code Online (Sandbox Code Playgroud)

编辑

我有一个重定向 action_controller.rb

  def after_sign_in_path_for(user)
    home_mypath_path
  end
Run Code Online (Sandbox Code Playgroud)

我认为这会干扰登录.

ruby-on-rails datepicker ruby-on-rails-4

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

在 ScrollView 中将文本对齐为前导 - SWIFTUI

我有一个ScrollView

    ScrollView {
        VStack (alignment: .leading) {
            Text("\(userData.username), \(userData.age)")
                .fontWeight(.semibold)
                .font(Font.system(size:30))
        }
    }
Run Code Online (Sandbox Code Playgroud)

输出是:

在此处输入图片说明

我尝试翻转堆栈并在其中包含滚动视图,但得到了相同的结果。

我的工作是将它放在一个 HStack 中并添加一个 Spacer()

HStack {
         Text("\(userData.username), \(userData.age)")
             .fontWeight(.semibold)
             .font(Font.system(size:30))
             .padding([.leading])
         Spacer()
}
Run Code Online (Sandbox Code Playgroud)

这可以解决问题,但我认为这不是理想的方式。这是唯一的方法吗?或者是否有更好的解决方案在滚动视图中垂直对齐文本?

uiscrollview swiftui

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

SwiftUI RoundedRectangle 在底部被切除

我有一个快速RoundedRectangle

ScrollView(.horizontal, showsIndicators: false) {
            Group {
                HStack {
                    if let height = height {
                        if height != "" {
                            aboutMeItem(info: height, image: "ruler").frame(minWidth: 20)
                        }
                    }
                }
                .frame(minHeight: 70, maxHeight: 70)
                .overlay(RoundedRectangle(cornerRadius: 15).stroke(Color("darkGrey"), lineWidth: 3))
                .padding([.leading,.top,.trailing])
            }
        }
Run Code Online (Sandbox Code Playgroud)

我的输出是:

在此输入图像描述

由于某种原因,底线被稍微切掉,您看不到完整的线宽。

Iv 尝试删除其下方的视图,以防有东西覆盖它,但事实并非如此。我尝试过弄乱 和frame minmaxHeight但无论如何,那仍然是一样的。

swift swiftui

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

链接到最后的帖子 - rails

我试着去link_toshow一个行动post.

在我的controller身上:

@post = Post.all
Run Code Online (Sandbox Code Playgroud)

在我看来,我试图将它链接到最后一个帖子,如下所示:

<%= link_to @post.last do %>
 <%= @post.last.title %>
<% end %>
Run Code Online (Sandbox Code Playgroud)

但它没有带我到那篇文章的节目页面?

ruby ruby-on-rails ruby-on-rails-4

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

使用多个值ruby访问哈希

我有一个哈希

h = Hash.new{|hsh,key| hsh[key] = [] }
Run Code Online (Sandbox Code Playgroud)

它的值存储为数组

Iv添加到键的值数组,如下所示:

h[@name] << @age
h[@name] << @grade
Run Code Online (Sandbox Code Playgroud)

我试图访问这样的年龄

puts h[:@name][0]
Run Code Online (Sandbox Code Playgroud)

但它不起作用?

有没有更好的方法呢?

什么即时试图做的是创建一个哈希那里是具有价值负荷的关键:比如key=>name和值相等age,address,gender

ruby

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

SwiftUI - 导航栏颜色更改未应用于状态栏

我有以下几点:

var body: some View {
        NavigationView {
            VStack {
                 Text("Hello")
            }.navigationBarTitle("Edit Profile", displayMode: .inline)
             .background(NavigationConfiguration { nc in
                 nc.navigationBar.barTintColor = .red
                 nc.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.black]
            })
        }.navigationViewStyle(StackNavigationViewStyle())
}
Run Code Online (Sandbox Code Playgroud)

对于导航栏的配置,我有:

struct NavigationConfiguration: UIViewControllerRepresentable {
    var configuration: (UINavigationController) -> Void = { _ in }
    func makeUIViewController(context: UIViewControllerRepresentableContext<NavigationConfiguration>) -> UIViewController {
        UIViewController()
    }
    func updateUIViewController(_ uiViewController: UIViewController, context: UIViewControllerRepresentableContext<NavigationConfiguration>) {
        if let nc = uiViewController.navigationController {
            self.configuration(nc)
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是由于某种原因,顶部状态栏被排除在外,并且没有对其应用颜色:

状态栏图片

如何将红色也应用于导航栏上方的状态栏,我希望它是相同的颜色。

我试过下面的,但这失败了:

init() {
    UINavigationBar.appearance().backgroundColor = .red
}
Run Code Online (Sandbox Code Playgroud)

uinavigationbar uinavigationcontroller swift swiftui swiftui-navigationlink

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

SwiftUI - LazyVGrid 间距

我的文件LazyVGrid中有类似的内容SearchView.swift

let layout = [
    GridItem(.flexible()),
    GridItem(.flexible())
]

NavigationView {
     ZStack {
        VStack {
           ....Some other stuff here
           ScrollView (showsIndicators: false) {
                    LazyVGrid(columns: layout) {
                        ForEach(searchViewModel.allUsers, id: \.uid) { user in
                            NavigationLink(destination: ProfileDetailedView(userData: user)) {
                                profileCard(profileURL: user.profileURL, username: user.username, age: user.age, country: user.city)
                            }
                        }
                    }
                }
           }
      }
}
Run Code Online (Sandbox Code Playgroud)

我的 profileCard.swift 看起来像:

var body: some View {
    ZStack {
        Image.image(urlString: profileURL,
                 content:  {
                    $0.image
                        .resizable()
                        .aspectRatio(contentMode: .fill)
                        
                 }
        )
        .frame(width: 185, height: 250)
        .overlay(
            LinearGradient(gradient: Gradient(colors: …
Run Code Online (Sandbox Code Playgroud)

swift swiftui

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

检查句子是否包含数组中的任何单词

splitDescription = work.workdescription.downcase.split(' ')

keywords = ['teamwork', 'developed', 'enhanced', 'transformed', 'achieved','grew', 'introduced', 'project', 'awarded',
             'planned','supervised','created','designed','discovered','evaluated','promoted','represented','completed',
             'devised','liaised','controlled','researched','organised','achieved','managed','analysed','assessed','conducted',
             'solved','responsible for','responsibilities']

splitDescription.select {|word| word.include?(keywords)}.each do |word|
    new_score += 0.5
end
Run Code Online (Sandbox Code Playgroud)

我有一个splitDescription拆分并存储描述.

我想看看是否有任何关键字都在splitDescription和每个keywordsplitDescriptionnew_score0.5上升.

我正在尝试此代码,但它无法正常工作.

ruby ruby-on-rails ruby-on-rails-4

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