我想在swift中创建类似接口的功能,我的目标是当我调用另一个类时假设我正在调用API并且该类的响应我想反映到我当前的屏幕,在android界面中用来实现但应该是什么我在swift中使用它?任何人都可以帮我举个例子.android的代码如下:
public class ExecuteServerReq {
public GetResponse getResponse = null;
public void somemethod() {
getResponse.onResponse(Response);
}
public interface GetResponse {
void onResponse(String objects);
}
}
ExecuteServerReq executeServerReq = new ExecuteServerReq();
executeServerReq.getResponse = new ExecuteServerReq.GetResponse() {
@Override
public void onResponse(String objects) {
}
}
Run Code Online (Sandbox Code Playgroud) 我在表视图中添加了数据,并且我已经在第一个位置手动添加了"全选"选项,现在当用户选择第一个选项"全部选择"时,则手动选择"全部选择"选项未选中.选择全部,点击然后工作所有人或取消选择工作但信号选择所有不工作的人"全选"我尝试了下面的代码,但它不工作所以任何人都可以帮我解决这个问题?
var unchecked:Bool = true
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// create a new cell if needed or reuse an old one
let cell = ObjTableview.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! SelectUserCell
// set the text from the data model
cell.selectionStyle = UITableViewCellSelectionStyle.none
cell.lblStudentName.text = getStudentName[indexPath.row]
if UnAll == "unselect" {
if indexPath.row == 0 {
cell.btnCheckbox.setImage(UIImage(named: "unSelectedItem"), for: .normal)
}
if indexPath.row == Int(selectedNumber) {
cell.btnCheckbox.setImage(UIImage(named: "unSelectedItem"), for: .normal)
}
if indexPath.row == Int(unSelectNumber) { …
Run Code Online (Sandbox Code Playgroud) 我使用离子4并尝试更改背景色离子选择选项。
html。
<div *ngIf="listName.checked" class="colorselect color_{{color.slice(1,7)}}">
<ion-select (click)="prepareColorSelector()" (ionChange)="setColor(this.color,i)" [(ngModel)]="color">
<ion-select-option (ionSelect)="selectColor(optioncolor)" *ngFor="let optioncolor of colors" [value]="optioncolor" style="background-color:optioncolor">{{optioncolor}}</ion-select-option>
</ion-select>
</div>
Run Code Online (Sandbox Code Playgroud)
scss。
.colorselect {
.select-text {
width: 75px;
border-radius: 5px;
}
.alert-radio-inner,
.alert-radio-icon,
.alert-radio-label {
display: none;
}
&.colorselected:before {
content: '\2713';
color: white;
z-index: 999999;
width: 100%;
height: 100%;
font-size: 33px;
left: 50%;
top: 50%;
position: relative;
transform: translate(-50%);
}
$colorsToSelect: "#d435a2" "#a834bf" "#6011cf" "#0d0e81";
@each $colorOption in $colorsToSelect {
$colorWithoutHash: str-slice($colorOption, 2, 7);
&.color_#{$colorWithoutHash} {
&, & .select-text { …
Run Code Online (Sandbox Code Playgroud) 我正在使用sqlite文件从authorId获取diaryEntriesTeacher。当我打印变量authorId为nil时,它会生成authorId的以下对象:-
func applySelectQuery() {
checkDataBaseFile()
objFMDB = FMDatabase(path: fullPathOfDB)
objFMDB.open()
objFMDB.beginTransaction()
do {
let results = try objFMDB.executeQuery("select * from diaryEntriesTeacher", values: nil)
while results.next() {
let totalCount = results.resultDictionary
let authorId = totalCount?["authorId"]!
print("authorId",authorId)
}
}
catch {
print(error.localizedDescription)
}
print(fullPathOfDB)
self.objFMDB.commit()
self.objFMDB.close()
}
Run Code Online (Sandbox Code Playgroud)
我已在表视图中添加了数据,并且现在当用户选择第一个选项(即全选)时,我已在列表中的第一个位置手动添加了“全选”选项,然后在选择相同项时应选择列表中的所有项目并取消选择。我已经尝试过下面的代码,但它不起作用,所以任何人都可以帮助我解决这个问题
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = ObjTableview.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! SelectUserCell
for i in 0 ..< self.getStudentName.count {
cell.btnCheckbox.setImage(UIImage(named: "selectedItem"), for: .normal)
print (i) //i will increment up one with each iteration of the for loop
}
}
var unchecked = true
@IBAction func btnCheckBoxClick(_ sender: Any) {
if unchecked == true {
//(sender as AnyObject).setImage(UIImage(named: "selectedItem"), for: .normal)
cell?.btnCheckbox.setImage(UIImage(named: "selectedItem"), for: .normal)
//unchecked = false
let cello = ObjTableview.cellForRow(at: indexPath!)
print(cello!)
ObjTableview.reloadData() …
Run Code Online (Sandbox Code Playgroud) 我想提供带有ion-select 的选择选项。我在第一个位置手动添加了全选选项,当我全选视图未更新时。如何更新视图?
<ion-select multiple="true">
<ion-option (ionSelect)="allClicked()">select all</ion-option>
<ion-option *ngFor="let item of students ; let i = index" [selected]="item.checked" [value]="item">{{item.studentName}}</ion-option>
</ion-select>
Run Code Online (Sandbox Code Playgroud)
.ts
allClicked(){
if(this.isAll){
console.log(this.isAll)
this.isAll = false;
for (let temp of this.students) {
temp.checked = false;
}
}else{
this.isAll = true;
for (let temp of this.students) {
temp.checked = true;
}
}
console.log("all select event ");
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Ionic 2构建应用程序.我需要从图库或相机拍摄照片并将此照片上传到我的服务器.我有这个代码打开画廊并拍照.
accessGallery() {
this.camera.getPicture({
sourceType: this.camera.PictureSourceType.SAVEDPHOTOALBUM,
destinationType: this.camera.DestinationType.DATA_URL
}).then((imageData) => {
this.base64Image = 'data:image/jpeg;base64,' + imageData;
this.uploadFile();
}, (err) => {
console.log(err);
});
}
Run Code Online (Sandbox Code Playgroud)
将图像上传到服务器端
uploadFile() {
let body = new FormData();
body.append('images', this.base64Image);
let headers = new Headers({
'token': this.token,
'sid': this.sid,
'user': this.user,
'to': this.to,
'node': this.node,
'type':'image'
});
let options = new RequestOptions({ headers: headers });
console.log("header ----" +JSON.stringify(headers));
console.log("images data body----" +JSON.stringify(body));
this.http.post(this.apiurl,body,options)
.map(res => res.json())
.subscribe(
data => {
console.log(data);
},
err => { …
Run Code Online (Sandbox Code Playgroud) ion-select 的 css 问题,它在阴影根中有一个按钮。我需要默认值 --padding-top:10px,--padding-end:8px,--padding-bottom:10px,--padding-start:16px 为此,但它是第一个元素并假定应用的值如下所示。
下图包含离子选择的颜色框,无法控制此框的大小。离子选择的代码如下。有人能帮我吗?
<ion-col size="2" style="padding:0">
<div class="colorselect color_{{color.slice(1,7)}}">
<ion-select >
<ion-select-option (ionSelect)="selectColor(optioncolor)" *ngFor="let optioncolor of colors" [value]="optioncolor" >{{optioncolor}}
</ion-select-option>
</ion-select>
</div>
</ion-col>
Run Code Online (Sandbox Code Playgroud)
我在 ionic 4 中使用了节,成功安装后,当我尝试测试连接时,它会引发我的错误,例如……
离子 4 在 Module.createClient 初始化之前无法访问“客户端”
import * as XMPP from 'stanza';
export class StanzaTestPage implements OnInit {
client: any;
constructor() {
}
ngOnInit() {
this.createConn();
}
createConn() {
let that = this;
this.client = XMPP.createClient({
jid: 'testUser@testhost',
password: 'Pass_123',
transport: 'websocket',
wsURL: 'ws://***:1234/websock',
useStreamManagement: true
});
this.client.connect();
this.client.enableKeepAlive(/* { interval: 30 } */);
this.client.on('auth:failed', function (err) {
console.log("auth:failed.......");
console.log(err);
});
this.client.on('disconnected', function (err) {
console.log("disconnected.......");
console.log(err);
});
this.client.on('session:error', function (err) {
console.log("session:error.......");
console.log(err);
}); …
Run Code Online (Sandbox Code Playgroud) 收到令牌后,当令牌结束时,如何在登录后自动调用令牌?在同一页面上
Alamofire.request(urlString, method: .post, parameters: newPost, encoding: JSONEncoding.default)
.responseJSON { response in
if let json = response.result.value as? [String : Any]{
print("JSON: \(json)")
if UserDefaults.standard.bool(forKey: "logged_in") {
Token = json["Token"]! as! String
UserDefaults.standard.set(Token, forKey: "Token")
UserDefaults.standard.synchronize()
}
} else {
print("Did not receive json")
}
//expectation.fulfill()
}
Run Code Online (Sandbox Code Playgroud)