GVKun编程网logo

在iOS Carplay中延迟加载数据(apple carplay延迟)

11

本文将带您了解关于在iOSCarplay中延迟加载数据的新内容,同时我们还将为您解释applecarplay延迟的相关知识,另外,我们还将为您提供关于ajax延迟加载数据、android–在ListV

本文将带您了解关于在iOS Carplay中延迟加载数据的新内容,同时我们还将为您解释apple carplay延迟的相关知识,另外,我们还将为您提供关于ajax延迟加载数据、android – 在ListView中延迟加载图像、angular – 如何在延迟加载的模块中提供服务,并将该服务限定为延迟加载的模块及其组件?、angularjs – 在Angular中为ng-include延迟加载数据的首选方法是什么?的实用信息。

本文目录一览:

在iOS Carplay中延迟加载数据(apple carplay延迟)

在iOS Carplay中延迟加载数据(apple carplay延迟)

用户在Carplay中滚动时如何延迟加载项目?

我正在使用MPPlayableContentDataSource中的beginLoadingChildItems加载
第一组项目,但是当用户滚动到
页面底部时如何调用下一页?

答案1

小编典典

The way you can achieve this is inside the following function:

func beginLoadingChildItems(at indexPath: IndexPath, completionHandler: @escaping (Error?) -> Void)

As Example:

if (indexPath[componentIndex] + 1) % Threshold == 0 { // Threshold is Your Defined Batch Size    // Load the next corresponding batch}

Load your lazy data, then call:

completionHandler(nil) // In case of no error has occurred

,but firstly, you need to return the total items count correctly in the
following function:

func numberOfChildItems(at indexPath: IndexPath) -> Int

Something like the below,

class YourDataSource : MPPlayableContentDataSource {    private var items = [MPContentItem]()    private var currentBatch = 0    func beginLoadingChildItems(at indexPath: IndexPath, completionHandler: @escaping (Error?) -> Void) {        // indexPath[1]: is current list level, as per CarPlay list indexing (It''s an array of the indices as ex: indexPath = [0,1] means Index 0 in the first level and index 1 at the second level).        // % 8: Means each 8 items, I will perform the corresponding action.       // currentBatch + 1 == nextBatch, This check in order to ensure that you load the batches in their sequences.        let currentCount = indexPath[1] + 1        let nextBatch = (currentCount / 8) + 1        if currentCount % 8 == 0 && currentBatch + 1 == nextBatch {            // Load the next corresponding batch             YourAPIHandler.asyncCall { newItems in                self.currentBatch = self.currentBatch + 1                items.append(newItems)                completionHandler(nil)                MPPlayableContentManager.shared().reloadData()            }        } else {            completionHandler(nil)        }    }}func numberOfChildItems(at indexPath: IndexPath) -> Int {    return self.items.count}

ajax延迟加载数据

ajax延迟加载数据

接收返回的json数据,触发了滚动事件之后,开始取出数据
$(window).scroll(function(){
		$('#text').val($(document).scrollTop());
		//如果滚动到下面的时候,触发ajax事件获取数据,显示在页面上。
		if($(document).scrollTop() > $(window).height()){
			$.ajax({
				type : 'POST',url : ThinkPHP['ROOT'] + '/Index/getBottomPic',dataType: 'json',success: function(data,textStatus,jqXHR){
					console.log(data.pic2);
					var pichtml = '';
					var pichtm2 = '';
					var i = 1; var j = 1;
					//第一个选项卡的内容
					$(data.pic1).each(function(k,v){
						pichtml += "<a><div><img src= '"+v.img_url+"' /></div><div><b>"+v.title+"</b></div></a>";						
						i++;
					});
					$('#pic1').append(pichtml);
					//第二个选项卡的内容
					$(data.pic2).each(function(k,v){
						pichtm2 += "<a><div><img src= '"+v.img_url+"' /></div><div><b>"+v.title+"</b></div></a>";						
						j++;
					});
					$('#pic2').append(pichtm2);
				}
			});
			$(window).unbind("scroll");
		}
	});

android – 在ListView中延迟加载图像

android – 在ListView中延迟加载图像

我使用ListView来显示与这些图像相关的一些图像和标题.我从互联网上获取图像.有没有办法延迟加载图像,以便文本显示时,UI不会被锁定,图像会在下载时显示?

图像总数不固定.

解决方法:

这是我创建的用于保存我的应用当前正在显示的图像的内容.请注意,这里使用的“Log”对象是围绕Android内部最终Log类的自定义包装器.

package com.wilson.android.library;

/*
 Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
*/
import java.io.IOException;

public class DrawableManager {
    private final Map<String, Drawable> drawableMap;

    public DrawableManager() {
        drawableMap = new HashMap<String, Drawable>();
    }

    public Drawable fetchDrawable(String urlString) {
        if (drawableMap.containsKey(urlString)) {
            return drawableMap.get(urlString);
        }

        Log.d(this.getClass().getSimpleName(), "image url:" + urlString);
        try {
            InputStream is = fetch(urlString);
            Drawable drawable = Drawable.createFromStream(is, "src");


            if (drawable != null) {
                drawableMap.put(urlString, drawable);
                Log.d(this.getClass().getSimpleName(), "got a thumbnail drawable: " + drawable.getBounds() + ", "
                        + drawable.getIntrinsicHeight() + "," + drawable.getIntrinsicWidth() + ", "
                        + drawable.getMinimumHeight() + "," + drawable.getMinimumWidth());
            } else {
              Log.w(this.getClass().getSimpleName(), "Could not get thumbnail");
            }

            return drawable;
        } catch (MalformedURLException e) {
            Log.e(this.getClass().getSimpleName(), "fetchDrawable Failed", e);
            return null;
        } catch (IOException e) {
            Log.e(this.getClass().getSimpleName(), "fetchDrawable Failed", e);
            return null;
        }
    }

    public void fetchDrawableOnThread(final String urlString, final ImageView imageView) {
        if (drawableMap.containsKey(urlString)) {
            imageView.setimageDrawable(drawableMap.get(urlString));
        }

        final Handler handler = new Handler() {
            @Override
            public void handleMessage(Message message) {
                imageView.setimageDrawable((Drawable) message.obj);
            }
        };

        Thread thread = new Thread() {
            @Override
            public void run() {
                //Todo : set imageView to a "pending" image
                Drawable drawable = fetchDrawable(urlString);
                Message message = handler.obtainMessage(1, drawable);
                handler.sendMessage(message);
            }
        };
        thread.start();
    }

    private InputStream fetch(String urlString) throws MalformedURLException, IOException {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet request = new HttpGet(urlString);
        HttpResponse response = httpClient.execute(request);
        return response.getEntity().getContent();
    }
}

angular – 如何在延迟加载的模块中提供服务,并将该服务限定为延迟加载的模块及其组件?

angular – 如何在延迟加载的模块中提供服务,并将该服务限定为延迟加载的模块及其组件?

在angular docs FAQ部分中,它指出,“与启动时加载的模块的提供者不同,延迟加载模块的提供者是模块范围的.” link

这里的’module-scoped’是指模块还是扩展为包含属于该模块的所有组件?

我问的原因是因为我有一个带有2个属于它的组件的延迟加载模块.我在模块中注册了一个服务,但由于某种原因,每个组件都获得了该服务的不同实例.

为了在我的延迟加载模块中提供LazyModuleService并将该服务限定为延迟加载的模块及其组件,我需要更改什么?请包含所需的任何其他文件.我试图做一个通用的例子来帮助其他可能找到这个问题的人.

延迟加载模块:

import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { Component1 } from './component1.component';
import { Component2 } from './component2.component';
import { LazyModuleService } from './lazy-module.service';

@NgModule({
  imports: [
    CommonModule,],declarations: [
    Component1,Component2,})

export class LazyLoadedModule { }

解决方法

延迟加载的工作原理:

经过深入调查后,似乎问题与如何实现延迟加载有关.

在您的情况下,您的延迟加载模块实际上已路由到其中的两个不同组件 – 这两个组件都直接公开为Router.forChild路由.但是,因此,当您导航到每个组件时,会为每个组件添加一个单独的延迟加载模块提供程序实例.

由于您实际上希望延迟加载模块中的所有组件共享其提供的服务的相同实例,因此您需要创建一个“根”组件,然后让您的两个组件成为该根组件的子组件.

似乎在延迟加载时,模块中的提供程序将添加到模块根部的组件的注入器中.由于您有两个“根组件”,因此每个组件都有不同的服务实例.

解决方案是创建一个单个根组件,其注入器将接收延迟加载的服务,然后可以由任何子组件共享.

angularjs – 在Angular中为ng-include延迟加载数据的首选方法是什么?

angularjs – 在Angular中为ng-include延迟加载数据的首选方法是什么?

我在使用ng-repeat循环遍历对象列表时创建(父)行.我还创建了一个隐藏的行.可见行包含soms基本数据,隐藏行(detail)包含所有数据.我希望在单击父行时可以看到详细信息行.而且我只想在细节行变得可见时加载数据.此外,一旦已加载行的详细信息,我不想再次访问服务器.

我为详细信息视图创建了一个部分,所以我的代码如下所示:

<div ng-include="'/Customer/View'"></div>

当然我可以找到/ Customer / View / 12,但是即使没有请求,也会加载所有数据.

那么,实现这个目标的方法是什么?有人能指出我正确的方向吗?

解决方法

实现此目的的一种方法是在 ngInclude上使用变量,并在单击父行时设置它.

Here is a sample fiddle,如果您使用Chrome(或其他浏览器)的网络标签,则可以看到在您点击某个项目之前不会请求包含中的网址.

<div ng-repeat="item in items" ng-click="url = item">
    <span ng-hide="url">Click to load</span>
    <span ng-show="url">Loaded item {{url}}</span>
    <div ng-include="url"></div>
</div>

从高层次来看,这里发生的是:

> url最初未设置为任何内容,因此ng-include无法获取
>单击父项时,使用ng-click将url变量设置为某个值(您可以使用范围函数来更好地控制URL,如this example所示)
>现在设置了该范围内的变量,因此ng-include可以获取点击时请求的URL

注意:您不必在javascript中声明url变量,因为ngRepeat为您循环的每个项目创建了一个新的作用域,因此设置变量的单击操作只会影响您正在使用的当前作用域.

今天的关于在iOS Carplay中延迟加载数据apple carplay延迟的分享已经结束,谢谢您的关注,如果想了解更多关于ajax延迟加载数据、android – 在ListView中延迟加载图像、angular – 如何在延迟加载的模块中提供服务,并将该服务限定为延迟加载的模块及其组件?、angularjs – 在Angular中为ng-include延迟加载数据的首选方法是什么?的相关知识,请在本站进行查询。

本文标签: