关于objective-c–隐藏表视图,直到加载所有数据–IOS和io是什么意思的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于angular–无法解析AuthenticationServ
关于objective-c – 隐藏表视图,直到加载所有数据 – IOS和io是什么意思的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])、ios – Objective-C / NSObject指针与C指针进行比较、ios – Objective-C – 向NSArray添加addObject、ios – Objective-c将子视图添加到视图的底部等相关知识的信息别忘了在本站进行查找喔。
本文目录一览:- objective-c – 隐藏表视图,直到加载所有数据 – IOS(io是什么意思)
- angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])
- ios – Objective-C / NSObject指针与C指针进行比较
- ios – Objective-C – 向NSArray添加addObject
- ios – Objective-c将子视图添加到视图的底部
objective-c – 隐藏表视图,直到加载所有数据 – IOS(io是什么意思)
UITableView – hide all groups/cells while data is loading
他们说将部分设置为0直到加载所有数据,然后重新加载单元格和表格视图,但他们没有详细说明如何操作.
非常感谢
解决方法
[self.tableView setHidden:YES];
直到您获得所有数据并使其可见
[self.tableView setHidden:NO];
angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])
Can’t resolve all parameters for AuthenticationService: ([object Object],?,[object Object])
我已经检查了几乎每个主题,并尝试了多种方法来解决它,但仍然无法在第二天击败它.
我试图像这样在appService中注入第一个authService但是得到了同样的错误
@Inject(forwardRef(() => AuthenticationService)) public authService: AuthenticationService
我检查了所有DI和服务内部的导入顺序,在我看来一切都是正确的
如果有人可以帮我处理它,我很感激.
Angular 4.0.0
AuthService
import { Injectable } from '@angular/core'; import {Http,Headers,Response} from '@angular/http'; import 'rxjs/add/operator/toPromise'; import {Observable} from 'rxjs/Rx'; import {AppServices} from "../../app.services"; import {Router} from "@angular/router"; @Injectable() export class AuthenticationService { public token: any; constructor( private http: Http,private appService: AppServices,private router: Router ) { this.token = localStorage.getItem('token'); } login(username: string,password: string): Observable<boolean> { let headers = new Headers(); let body = null; headers.append("Authorization",("Basic " + btoa(username + ':' + password))); return this.http.post(this.appService.api + '/login',body,{headers: headers}) .map((response: Response) => { let token = response.json() && response.json().token; if (token) { this.token = token; localStorage.setItem('Conform_token',token); return true; } else { return false; } }); } logout(): void { this.token = null; localStorage.removeItem('Conform_token'); this.router.navigate(['/login']); } }
应用服务
import {Injectable} from '@angular/core'; import {Headers,Http,RequestOptions} from '@angular/http'; import {Router} from "@angular/router"; import {AuthenticationService} from "./auth/auth.service"; import 'rxjs/add/operator/toPromise'; import {Observable} from 'rxjs/Rx'; @Injectable() export class AppServices { api = '//endpoint/'; public options: any; constructor( private http: Http,private router: Router,public authService: AuthenticationService // doesn't work // @Inject(forwardRef(() => AuthenticationService)) public authService: AuthenticationService // doesn't work either ) { let head = new Headers({ 'Authorization': 'Bearer ' + this.authService.token,"Content-Type": "application/json; charset=utf8" }); this.options = new RequestOptions({headers: head}); } // ==================== // data services // ==================== getData(): Promise<any> { return this.http .get(this.api + "/data",this.options) .toPromise() .then(response => response.json() as Array<Object>) .catch((err)=>{this.handleError(err);}) }
应用模块
import { browserModule } from '@angular/platform-browser'; import { browserAnimationsModule } from '@angular/platform-browser/animations'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import {BaseRequestOptions,HttpModule} from '@angular/http'; import { MaterialModule} from '@angular/material'; import {FlexLayoutModule} from "@angular/flex-layout"; import 'hammerjs'; import { routing,appRoutingProviders } from './app.routing'; import { AppServices } from './app.services'; import {AuthGuard} from "./auth/auth.guard"; import {AuthenticationService} from "./auth/auth.service"; import {AppComponent} from './app.component'; import {AuthComponent} from './auth/auth.component'; import {NotFoundComponent} from './404/not-found.component'; import { HomeComponent } from './home/home.component'; @NgModule({ declarations: [ AppComponent,AuthComponent,NotFoundComponent,HomeComponent ],imports: [ browserModule,browserAnimationsModule,FormsModule,HttpModule,routing,MaterialModule,FlexLayoutModule ],providers: [AppServices,AuthGuard,AuthenticationService],bootstrap: [AppComponent] }) export class AppModule { }
解决方法
你可以使用
export class AuthenticationService { public token: any; appService: AppServices; constructor( private http: Http,// private appService: AppServices,injector:Injector; private router: Router ) { setTimeout(() => this.appService = injector.get(AppServices)); this.token = localStorage.getItem('token'); }
另见DI with cyclic dependency with custom HTTP and ConfigService
要避免使用setTimeout,您还可以从AppService的构造函数中设置AuthenticationService.appService(或者相反)
ios – Objective-C / NSObject指针与C指针进行比较
例如:
Nsstring *string1 = @"This is a string"; Nsstring *string2; string2 = string 1;
在C中,(如果我错了请纠正我)this = b / w 2指针使它们指向相同的“指针”.这意味着更改string1也应该更改string2.但它似乎没有像这样工作,并且Nsstrings无论如何都是严格不变的,所以这增加了一些混乱.
string1 = @"new string";
如果这些指针像C指针一样操作,那么这不应该改变string2,因为它指向与string1相同的位置.此外,在C中,必须先将指针指定给指针对象才能取消引用.此规则似乎不适用于NSObjects.什么是’@’在做什么?最后,为什么我没有看到NSObjects的解引用发生如下:
*string1 = @"modifying the string"; //shouldn't this be how to access the contents of the pointer string1 if it operates like a c pointer?
有人可以对Objective-C指针下的内容以及它们与C指针的比较和对比有所了解吗?任何帮助将不胜感激.
解决方法
char *a = "hello"; char *b = a; b = "world";
然后a不会改变.当对象可变时,对多个指针指向的公共对象所做的更改将变为可见. Nsstring和C字符串文字都不可变,所以让我们构建一个不同的例子:
NSMutableString *string1 = [NSMutableString string:@"This is a string"]; NSMutableString *string2; string2 = string1; NSLog(string1); NSLog(string2); [string1 appendString:@" (a very long one!)"]; NSLog(string1); NSLog(string2);
现在string2“看到”对string1所做的更改,因为该对象是可变的.
C中的类似示例如下所示:
char[] a = "hello"; char b = a; printf("%s %s\n",a,b); strcpy(b,"world"); printf("%s %s\n",b);
ios – Objective-C – 向NSArray添加addObject
NSArray *shoppingList = @[@"Eggs",@"Milk"]; Nsstring *flour = @"Flour"; [shoppingList addobject:flour]; shoppingList += @["Baking Powder"]
错误信息
/Users/xxxxx/Documents/iOS/xxxxx/main.m:54:23: No visible @interface for 'NSArray' declares the selector 'addobject:'
请指教.谢谢.
解决方法
如果您可以控制您创建的数组,请使shoppingList NSMutableArray:
NSMutableArray *shoppingList = [@[@"Eggs",@"Milk"] mutablecopy]; [shoppingList addobject:flour]; // Works with NSMutableArray
否则,使用效率较低
shoppingList = [shoppingList arrayByAddingObject:flour]; // Makes a copy
ios – Objective-c将子视图添加到视图的底部
解决方法
[view insertSubview:aView atIndex:0]
我们今天的关于objective-c – 隐藏表视图,直到加载所有数据 – IOS和io是什么意思的分享已经告一段落,感谢您的关注,如果您想了解更多关于angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])、ios – Objective-C / NSObject指针与C指针进行比较、ios – Objective-C – 向NSArray添加addObject、ios – Objective-c将子视图添加到视图的底部的相关信息,请在本站查询。
本文标签: