Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionViewFlowLayout exception when executing XHR-Request in NativeScript

I tried to execute an POST-Request to a given API via Xcode 7. My error is:

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.

The code I tried to execute:

TypeScript:

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"),
                message: translate.instant("VOTE_FAILED_MSG"),
                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;
}

I am not sure how to handle this error, does anyone have a hint for me? :D

like image 946
Rüdiger Avatar asked Aug 28 '17 08:08

Rüdiger


1 Answers

It turns out that I used a appSettings.setNumber(...); in the application-settings module of my application. I changed it into appSettings.setString(); and formatted the parameter into a String and now it worked. Let's see if that did really do the trick...

like image 150
Rüdiger Avatar answered Oct 29 '22 01:10

Rüdiger