小编Ham*_*ian的帖子

44
推荐指数
3
解决办法
2万
查看次数

主键属性“名称”在对象“ RealmSwiftPermissionRole”上不存在

我在我的swift项目中使用RealmSwift作为数据库。今天,在Xcode-beta版本11中打开我的项目后,我的应用因以下错误而崩溃:

由于未捕获的异常“ RLMException”而终止应用程序,原因:对象“ RealmSwiftPermissionRole”上不存在“主键属性”名称”

我的应用程序可以在以前版本的Xcode(10.2.1)上正常运行。 RealmSwiftPermissionRoleRealm中的一个类,我无权访问。也许在他们的功能更新中,他们修复了此错误,但就目前而言,我进行了很多搜索,但未找到任何解决方案。(我清理了项目,从模拟器中删除了该应用,然后再次运行了该项目,但没有任何改变。)有什么建议吗?

xcode realm

24
推荐指数
3
解决办法
6113
查看次数

如何将RecyclerView放在工具栏下方以及TabLayout和ViewPager上方以自定义方式处理对滚动的响应?

我想创建一个如下图所示的布局:

在此输入图像描述

CoordinatorLayout包含:

  1. CollapsingToolbarLayout(包含ImageView和工具栏)
  2. RecyclerView
  3. TabLayout
  4. ViewPager(它的每个片段都包含一个RecyclerView)

我想以这种方式回应滚动事件:

  1. CollapsingToolbarLayout通过滚动展开和折叠
  2. 工具栏顶到顶部,直到TabLayout到达顶部
  3. 在该工具栏向上滚动并且TabLayout坚持到顶部

我在使用CollapsingToolbarLayout和TabLayout之间的RecyclerView时遇到问题.我可以在不使用RecyclerView的情况下实现这种布局(我将CollapsingToolbarLayout和TabLayout放在AppBarLayout中,将ViewPager放在它外面,在CoordinatorLayout内).

我的问题:

  1. 我应该把RecyclerView放在哪里?
  2. 我为每个布局设置了哪个&哪里layout_scrollFlags和哪个layout_behavior

似乎AppBarLayout的高度有限.当我将RecyclerView放在AppBarLayout中时,只有RecyclerView的一部分可见,并且TabLayout也会消失.

我阅读了很多像这样的教程和许多像这一个这个的问题,但是没有它们帮助我.

android android-toolbar android-recyclerview android-coordinatorlayout android-collapsingtoolbarlayout

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

自定义UI TableViewCell选择了backgroundcolor swift

我试图使用Swift更改自定义选定的TableViewCell的外观.

我需要通过设计师还是以编程方式完成?

我尝试了以下方法:

在此输入图像描述

这是我的代码:

@IBOutlet var tableView: UITableView!


    var tableData: [String] = ["One", "Two", "Three", "Four"]

    override func viewDidLoad() {
        super.viewDidLoad()


        // Register custom cell
        var nib = UINib(nibName: "vwTblCell", bundle: nil)
        tableView.registerNib(nib, forCellReuseIdentifier: "cell")

    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.tableData.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell     {

        var cell:TblCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as TblCell

        cell.lblCarName.text = tableData[indexPath.row]
        cell.imgCarName.image = UIImage(named: tableData[indexPath.row])

        return cell

    }

    func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) { …
Run Code Online (Sandbox Code Playgroud)

selected uitableview swift

15
推荐指数
7
解决办法
5万
查看次数

在Android中使用改进2上传二进制文件

我想在Android中将二进制文件上传到服务器.我通过邮递员测试Api方法:

在此输入图像描述

没关系,你可以看到还有另一个选项可以上传文件作为表单数据(键,值):

在此输入图像描述

每个教程(如教程)都描述了如何上传文件multipart/form-data:

 // create RequestBody instance from file
    RequestBody requestFile =
            RequestBody.create(MediaType.parse("multipart/form-data"), file);

    // MultipartBody.Part is used to send also the actual file name
    MultipartBody.Part body =
            MultipartBody.Part.createFormData("picture", file.getName(), requestFile);
Run Code Online (Sandbox Code Playgroud)

我搜索了很多,但找不到任何方法上传文件作为二进制与retrofit2.

改造存储库中只有一个问题,询问我如何在改装2.0测试版中发布图像二进制文件?.我用它的解决方案:

API服务:

@POST("trip/{tripId}/media/photos")
Call<MediaPost> postEventPhoto(
    @Path("eventId") int tripId,
    @Header("Authorization") String accessToken,
    @Query("direction") String direction,
    @Body RequestBody photo);
Run Code Online (Sandbox Code Playgroud)

呼叫者:

InputStream in = new FileInputStream(new File(media.getPath()));
byte[] buf;
buf = new byte[in.available()];
while (in.read(buf) != -1);
RequestBody requestBody = RequestBody
    .create(MediaType.parse("application/octet-stream"), buf);
Call<MediaPost> …
Run Code Online (Sandbox Code Playgroud)

android retrofit2

13
推荐指数
3
解决办法
7044
查看次数

如何改变CollapsingToolbarLayout标题的方向?

我在我的项目中使用了Design Support Library,想要将CollapsingToolbarLayout的标题从ltr更改为rtl(如下所示).我可以这样做吗?

CollapsingToolbarLayout的标题是从右到左

我检查了这个链接,但找不到任何有用的东西.这个设计的布局尚未准备好,但这是一个类似的xml:

<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/detail_backdrop_height"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginStart="48dp"
        app:expandedTitleMarginEnd="64dp">

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin" />

    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingTop="24dp">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/card_margin">

            <LinearLayout
                style="@style/Widget.CardContent"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Info"
                    android:textAppearance="@style/TextAppearance.AppCompat.Title" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/cheese_ipsum" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/card_margin"
            android:layout_marginLeft="@dimen/card_margin"
            android:layout_marginRight="@dimen/card_margin">

            <LinearLayout
                style="@style/Widget.CardContent"
                android:layout_width="match_parent" …
Run Code Online (Sandbox Code Playgroud)

java android right-to-left

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

在Google Play中禁用自动商店列表翻译

如何禁用我的应用说明的自动翻译?我真的不想用> 70种语言翻译我的应用程序......我的客户只使用英语.

android translation google-play

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

Swift 包解析失败,因为多个目标命名了同一框架

我有 2 个本地 Swift 软件包:LibALibB. LibA 和 LibB 都依赖于相同的框架(AmazonIVSPlayer)。我想将两者添加到我的项目中,但出现以下错误:

LibA和中名为“AmazonIVSPlayer”的多个目标LibB

两个库的 Package.swift 如下所示:

import PackageDescription

let package = Package(
    name: "LibA",
    products: [
        // Products define the executables and libraries a package produces, and make them visible to other packages.
        .library(
            name: "LibA",
            targets: ["LibA","AmazonIVSPlayern"]),
    ],
    dependencies: [
        // Dependencies declare other packages that this package depends on.
        // .package(url: /* package url */, from: "1.0.0"),
    ],
    targets: [
        // Targets are …
Run Code Online (Sandbox Code Playgroud)

ios swift swift-package-manager

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

Rails机架攻击宝石油门

我不知道为什么我不能使用机架攻击宝石这里我做了什么

的Gemfile

gem 'rack-attack' 
Run Code Online (Sandbox Code Playgroud)

我安装了宝石

配置/ application.rb中

config.middleware.use Rack::Attack
Run Code Online (Sandbox Code Playgroud)

初始化/机架attack.rb

class Rack::Attack

throttle('logins/ip', :limit => 5, :period => 60.seconds) do |req|
  if req.path == '/login' && req.post?
  Rails.logger.error("Rack::Attack Too many login attempts from IP: #{req.ip}")
  req.ip 
  end
end

end
Run Code Online (Sandbox Code Playgroud)

的routes.rb

post   'login'   => 'index#create'
root 'index#new'
get 'login' => 'index#new'
Run Code Online (Sandbox Code Playgroud)

我正在使用Rails 4.2.3和机架攻击宝石4.3.0

我想知道我想念的是什么

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

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

如何在NestedScrollView中随时(平滑地)获得滚动百分比?

我想在滚动时更改工具栏的alpha,如下所示:

在此输入图像描述

首先,工具栏是透明的,通过滚动到底部,它将越来越可见,最后它将是完全不透明(可见).

我的布局结构是:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_collapseMode="parallax">

            ....

        </RelativeLayout>

    </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.widget.NestedScrollView
    android:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

         ....

    </android.support.v4.widget.NestedScrollView>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

嵌套的scrollview的内容将从服务器动态更改,所以我不知道它的高度.

我刚刚发现了两种检测scrollY的方法:

  1. addOnScrollChangedListener:

    scroll.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
     @Override
     public void onScrollChanged() {
        // use scroll.getScrollY()     
    }
    });
    
    Run Code Online (Sandbox Code Playgroud)
  2. setOnScrollChangeListener:

    scroller.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
    
    @Override
    public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
    
    }
    });
    
    Run Code Online (Sandbox Code Playgroud)

但这些方式都不顺利.例如,如果您检查scrollY(通过使用log.d())的值,您将看到如下内容:

scrollY: 58 …
Run Code Online (Sandbox Code Playgroud)

android scroll scrollview android-nestedscrollview

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