在 NativeScript 中执行 XHR-Request 时出现 UICollectionViewFlowLayout 异常
UICollectionViewFlowLayout exception when executing XHR-Request in NativeScript
我试图通过 Xcode 对给定的 API 执行 POST-请求 7. 我的错误是:
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"),
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;
}
我不确定如何处理这个错误,有没有人给我提示? :D
原来我在我的应用程序的application-settings
模块中使用了一个appSettings.setNumber(...);
。我将其更改为 appSettings.setString();
并将参数格式化为字符串,现在它可以工作了。让我们看看这是否真的有效...
我试图通过 Xcode 对给定的 API 执行 POST-请求 7. 我的错误是:
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"),
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;
}
我不确定如何处理这个错误,有没有人给我提示? :D
原来我在我的应用程序的application-settings
模块中使用了一个appSettings.setNumber(...);
。我将其更改为 appSettings.setString();
并将参数格式化为字符串,现在它可以工作了。让我们看看这是否真的有效...