【发布时间】:2018-02-05 11:09:30
【问题描述】:
我尝试通过 Xcode 7 对给定 API 执行 POST 请求。我的错误是:
未定义 UICollectionViewFlowLayout 的行为,因为: 项目高度必须小于 UICollectionView 的高度减去部分插入顶部和底部值,减去内容插入顶部和底部值。
相关的UICollectionViewFlowLayout实例是<_uialertcontrollercollectionviewflowlayout:>,它附在;层 = ;内容偏移:{0, 0}; contentSize: {0, 0}> 集合视图布局:<_uialertcontrollercollectionviewflowlayout:>。 在 UICollectionViewFlowLayoutBreakForInvalidSizes 处创建一个符号断点以在调试器中捕获它。
我尝试执行的代码:
打字稿:
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
【问题讨论】:
-
在使用 NativeScript Angular 模板时,我建议使用 Angular HTTP 模块,而不是 XMLHttpRequest。这个模块的使用示例可以在这里找到 - github.com/NativeScript/nativescript-sdk-examples-ng/tree/…
-
感谢您的评论,但这并没有改变设置的任何内容,因为这似乎是一个图形问题
-
看起来您的网格布局中的图像和按钮没有足够的高度。您可以尝试明确设置网格布局的高度以进行调整
-
我试过了,但没有成功。我现在发布了一个关于它如何为我工作的答案,但我不确定这是否能解决问题。
标签: ios xcode typescript xcode7 nativescript