加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 在NativeScript中执行XHR-Request时出现UICollectionView

发布时间:2020-12-14 19:38:24 所属栏目:百科 来源:网络整理
导读:我试图通过 Xcode 7对给定的API执行POST请求.我的错误是: the behavior of the UICollectionViewFlowLayout is not defined because: the item height must be less than the height of the UICollectionView minus the section insets top and bottom valu
我试图通过 Xcode 7对给定的API执行POST请求.我的错误是:

the behavior of the UICollectionViewFlowLayout is not defined because:
the item height must be less than the height of the UICollectionView minus the section insets top and bottom values,minus the content insets top and bottom values.

The relevant UICollectionViewFlowLayout instance is <_UIAlertControllerCollectionViewFlowLayout: 0x7f99fe411ea0>,and it is attached to ; layer = ; contentOffset: {0,0}; contentSize: {0,0}> collection view layout: <_UIAlertControllerCollectionViewFlowLayout: 0x7f99fe411ea0>.
Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.

我试图执行的代码:

打字稿:

makeRatingCall(userRating) {
    var score = userRating;
    var film_edition_id = "123456789";
    var computer_name = ConfigurationService.getUserData().user_username;
    var api_key = "key";
    return new Promise( function (resolve,reject) {
        let xhr = new XMLHttpRequest();
        xhr.open("POST","my-url" + this.formatParams({film_edition_id,score,computer_name,api_key }),true);
        xhr.setRequestHeader("Accept","application/json");
        xhr.onload = function() {
            if (xhr.readyState === 4 && xhr.status === 200) {
                resolve(JSON.parse(xhr.responseText).err_code);
            } else {
                reject(xhr.responseText);
            }
        }
        xhr.onerror = function( err ) {
            reject ( err );
        }
        xhr.send();
    });
}

formatParams = function ( params ){
    return "?" + Object.keys(params).map((key) => {
        return `${key}=${encodeURIComponent(params[key])}`
    }).join("&")
}

rateIt() {
    var translate = this.translateService;
    this.makeRatingCall( this.currentRating )
        .then(function ( err_code ) {
            if (err_code == 0) {
                dialogs.alert({
                    title: translate.instant("VOTE_SUCCESSFUL"),message: translate.instant("VOTE_SUCCESSFUL_MSG"),okButtonText: translate.instant("OK")
                });
                this.rateInteraction = false;
            } else if (err_code == 1) {
                dialogs.alert({
                    title: translate.instant("ALREADY_VOTED"),message: translate.instant("ALREADY_VOTED_MSG"),okButtonText: translate.instant("OK")
                });
            } else {
                dialogs.alert({
                    title: translate.instant("VOTE_FAILED"),message: translate.instant("VOTE_FAILED_MSG"),okButtonText: translate.instant("OK")
                });
            }
        } )
        .catch(function ( err ) {
            dialogs.alert({
                title: translate.instant("VOTE_FAILED"),okButtonText: translate.instant("OK")
            }); 

        });
}

HTML:

<GridLayout columns="*4,*,*" rows="*">
            <Button col="0" row="0" [text]="'SEND_RATING'|translate" class="send-rating-button" (onTap)="rateIt()"
            [isUserInteractionEnabled]="rateInteraction"></Button>
            <Image src="{{ user_rating_imageurls[0] }}" col="1" row="0" class="star-image" (onTap)="rateFromUser('1')"
                [isUserInteractionEnabled]="rateInteraction"></Image>
            <Image src="{{ user_rating_imageurls[1] }}" col="2" row="0" class="star-image" (onTap)="rateFromUser('2')"
                [isUserInteractionEnabled]="rateInteraction"></Image>
            <Image src="{{ user_rating_imageurls[2] }}" col="3" row="0" class="star-image" (onTap)="rateFromUser('3')"
                [isUserInteractionEnabled]="rateInteraction"></Image>
            <Image src="{{ user_rating_imageurls[3] }}" col="4" row="0" class="star-image" (onTap)="rateFromUser('4')"
                [isUserInteractionEnabled]="rateInteraction"></Image>
            <Image src="{{ user_rating_imageurls[4] }}" col="5" row="0" class="star-image" (onTap)="rateFromUser('5')"
                [isUserInteractionEnabled]="rateInteraction"></Image>
        </GridLayout>

CSS:

.send-rating-button {
    margin-top: 10;
    margin-left: 30;
    margin-right: 10;
    margin-bottom: 10;
    background-color: yellow;
}

.star-image {
    width: 30;
    margin: 10;
}

我不知道如何处理这个错误,有没有人给我一个暗示? :d

解决方法

事实证明我使用了appSettings.setNumber(…);在我的应用程序的应用程序设置模块中.我将其更改为appSettings.setString();并将参数格式化为一个字符串,现在它工作.让我们看看是否真的有这个诀窍……

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读