GVKun编程网logo

objective-c – 隐藏表视图,直到加载所有数据 – IOS(io是什么意思)

11

关于objective-c–隐藏表视图,直到加载所有数据–IOS和io是什么意思的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于angular–无法解析AuthenticationServ

关于objective-c – 隐藏表视图,直到加载所有数据 – IOSio是什么意思的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])、ios – Objective-C / NSObject指针与C指针进行比较、ios – Objective-C – 向NSArray添加addObject、ios – Objective-c将子视图添加到视图的底部等相关知识的信息别忘了在本站进行查找喔。

本文目录一览:

objective-c – 隐藏表视图,直到加载所有数据 – IOS(io是什么意思)

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])

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 { }

解决方法

AppServices和AuthenticationService之间存在循环依赖关系 – 这与Angular使用的构造函数注入无法实现.

你可以使用

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指针进行比较

ios – Objective-C / NSObject指针与C指针进行比较

根据apple objective-c文档,NSObject使用C指针来跟踪它们.我对iOS很新,并且将NSObjects上的指针操作与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指针的比较和对比有所了解吗?任何帮助将不胜感激.

解决方法

您将在C中获得与Objective-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

ios – Objective-C – 向NSArray添加addObject

如何使用此代码将对象添加到NSArray?尝试执行此操作时出现此错误消息.

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:'

请指教.谢谢.

解决方法

addobject适用于NSMutableArray,而不适用于NSArray,它是不可变的.

如果您可以控制您创建的数组,请使shoppingList NSMutableArray:

NSMutableArray *shoppingList = [@[@"Eggs",@"Milk"] mutablecopy];
[shoppingList addobject:flour]; // Works with NSMutableArray

否则,使用效率较低

shoppingList = [shoppingList arrayByAddingObject:flour]; // Makes a copy

ios – Objective-c将子视图添加到视图的底部

ios – Objective-c将子视图添加到视图的底部

是否有任何方法可以在其视图的“底部”添加子视图,例如当您使用图层时z = 0?我需要这个,因为当我产生物体时,它们需要在另一张照片下,而不是在上面.

解决方法

UIView的子视图的排序方式是数组的最后一个是最前面的一个,然后第一个(索引0)是后面的那个.所以,要将它插入“底部”,这样做就足够了:
[view insertSubview:aView atIndex:0]

我们今天的关于objective-c – 隐藏表视图,直到加载所有数据 – IOSio是什么意思的分享已经告一段落,感谢您的关注,如果您想了解更多关于angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])、ios – Objective-C / NSObject指针与C指针进行比较、ios – Objective-C – 向NSArray添加addObject、ios – Objective-c将子视图添加到视图的底部的相关信息,请在本站查询。

本文标签: