如果您对objective-c–iPhone:多个UIPickerViews感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于objective-c–iPhone:多个UIPi
如果您对objective-c – iPhone:多个UIPickerViews感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于objective-c – iPhone:多个UIPickerViews的详细内容,我们还将为您解答uiimagepickercontroller 多选的相关问题,并且为您提供关于angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])、iphone – NSObject和UIViewController有什么区别、iphone – Objective C Bezier Curve ReShaping、iphone – Objective C中方法的多个部分的有价值信息。
本文目录一览:- objective-c – iPhone:多个UIPickerViews(uiimagepickercontroller 多选)
- angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])
- iphone – NSObject和UIViewController有什么区别
- iphone – Objective C Bezier Curve ReShaping
- iphone – Objective C中方法的多个部分
objective-c – iPhone:多个UIPickerViews(uiimagepickercontroller 多选)
另外,我想将所选值放在不同UIPickerViews的UITextField中.
解决方法
-(void)numberOfComponentInPickerView:(UIPickerView*)thePickerView
你有thePickerView变量指向控件响应此操作,你现在需要做的就是区分你的UIPickerViews如下:
if (thePickerView == firstPickerView)
或使用Tag属性
if (thePickerView.tag == 1)
我会选择标签解决方案;比较int更快.
如何获取所选值:
对于UIPickerView的选定值,您可以使用委托来执行此操作:
-(void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
你需要在这里使用相同的技术;区分您的UIPickerView并获取该数据源的选定行,您就完成了
MyTextField.text = [theSelectedListArray objectAtIndex:row];
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(或者相反)
iphone – NSObject和UIViewController有什么区别
我想知道NSObject和UIViewController类之间有什么区别,以及我们将如何知道应该使用哪个类.
一些是用NSObject编写的,一些是在UIViewController中.
解决方法
Object-oriented programming (OOP) is a
programming paradigm using “objects” –
data structures consisting of data
fields and methods together with their
interactions – to design applications
and computer programs. […] An object-oriented program will usually contain different types of objects,each type corresponding to a particular kind of complex data to be managed or perhaps to a real-world object or concept such as a bank account,a hockey player,or a bulldozer.
在Objective-C中,所有对象都基于NSObject.现在就把它当作面值.如果你想使用一个Object,它将基于NSObject.所以,除非你使用int或float,否则你可能会使用基于NSObject的东西.
NSObject in-and-of-self,并不真正提供任何功能.这是对象的“起始位置”或“空白平板”.
您可以构建一个用于表示Animal的Object定义,如下所示:
@interface Animal : NSObject { } @property (assign) int age; - (Animal*)mateWith:(Animal*)lover; @end
在这个例子中,我们描述了一个基本的动物.这堂课基本上做了两件事;知道动物的年龄,并且可以与另一种动物交配以产生动物后代.
您将在该示例中注意到我们在NSObject上基于Object定义.
现在,假设我们要为人类创建一个定义;好吧,人类是,并且将永远是所有动物的子集.因此,我们可以重用Animal类定义中的所有逻辑来创建一个Human定义 – 我们可能这样做:
@interface Human : Animal { } - (void)lie; @end
在这个例子中,我们为一种名为“Human”的Object创建了一个新定义.我们只定义了一件事:一种让我们班级能够撒谎的方法 – 除了我们还能够交配,因为我们基于“动物”,而“动物”已经描述了如何交配.
回答你的问题:
UIViewController包含一个逻辑BUNCH,用于执行一些非常复杂的任务.大部分逻辑都是Cocoa Touch框架的一部分.
如果你正在制作一个“动物”课程,你不需要知道如何从屏幕上回复用户输入,你不需要知道如何管理UIView,你不需要跟踪parentViewControllers等等.因此,将我们的Animal类放在UIViewController上会很愚蠢.这是不使用UIViewController的时候.
现在,如果你在iPhone上创建一个用户界面屏幕,并且你想在用户点击一个按钮时执行一些例程 – 那么你需要所有UIViewController的东西,所以你要将它子类化.
我可以理解为什么,如果你不是来自面向对象的编程背景,你可能会对此感到困惑.看起来您需要创建的大部分内容都是ARE UIViewController子类.然而,当你探索OOP的世界时,你会发现不仅是对象是别人写的你可以使用的东西 – 但它们是你想要从头开始创建的东西,以完成你曾经在程序上做的事情. .
祝你在激动人心的旅途中好运.
我强烈建议你去当地的Barnes and Noble旅行,或者去亚马逊网站找一些关于这个主题的书籍 – 如果你有一个已经知道OOP的朋友,一个好的导师比学习自己快得多.
不要忘记,在iPhone上,你还必须处理内存管理.对于很多人来说这是一个难点 – 如果你不遵守规则,会引起很多麻烦.尽早了解它们,您将得到很好的服务.
希望有所帮助,
干杯.
资料来源:
> http://en.wikipedia.org/wiki/Object-oriented_programming
iphone – Objective C Bezier Curve ReShaping
我想要的是能够移动和重塑贝塞尔曲线,好像它是一块躺在桌子上被我的手指拉动的弦.即接触贝塞尔曲线的一部分并将其拉向一个方向以改变整体曲线的形状.
有谁知道如何做到这一点?任何帮助都会非常受欢迎.
提前致谢
解决方法
要做你想建议的事情,你首先需要回答“用户是否触摸曲线?”的问题.这与问题“是曲线的某个距离内的给定点”相同.这不是一个微不足道的问题,但可以计算出来.可能最简单的方法是沿曲线计算X点(其中X足够高以提供合理的精度),并检查每个点的距离.原则上,您也可以采用距离方程的导数并将其求解为零,但这需要迭代.根据我的经验,您可以足够快地计算所需的1000个左右的距离(即使在iPad 1上),这可能不值得额外的复杂性.
一旦发现用户实际上正在触摸曲线,就很容易找出最接近哪个控制点.在这一点上,最重要的是决定如何应对它.一些选择:
>沿用户移动的方向移动最近的控制点.您可能需要进行多次计算,直到找到通过触摸点的新曲线.这是最简单的方法,可能就在我开始的地方.
>您可以在触摸点处细分曲线并移动新创建的端点. (参见De Casteljau’s算法.)除非您调整其他控制点以创建匹配的斜率,否则这将产生尖角.这允许更多任意曲线,但是可能变得非常难以知道用户真正想要的是什么.您几乎肯定需要应用Ramer-Douglas-Peucker来保持曲线数量不受爆炸.
我目前对Objective-C中的Bézier曲线问题很感兴趣.您可能对我的first post on the subject感兴趣.我在GitHub的示例代码中可以在GitHub获得该领域的初步工作.希望本周我还有另一篇文章.你的特殊问题很有趣,所以我可以看到我可以围绕它建立什么.
iphone – Objective C中方法的多个部分
像Java和C一样,Obj.C可以接受多个参数,这很好,但是它表明目标C方法可以有多个名称,这些名称似乎与我没有很好的关系.
例如:
-(NSArray *)shipsAtPoint:(CGPoint)bombLocation withdamage:(BOOL)damaged;
在上面的例子中,有两个参数,bombLocation(返回类型CGPoint)和损坏的(返回类型BOOL),并且方法名称旁边似乎被拆分为shipatpoint:withdamage
我不明白这是怎么回事……
当它声明某个方法可以有多个名称时,它意味着什么?
这仅适用于需要多个参数的方法吗?或者,假设我想用单个名称命名我的方法,但是为它提供了多个参数,是可能的还是我必须为它提供多个名称,每个名称对应一个参数?如果是,那为什么呢?
感谢您与我的混乱!
总结
以上是小编为你收集整理的iphone – Objective C中方法的多个部分全部内容。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。
关于objective-c – iPhone:多个UIPickerViews和uiimagepickercontroller 多选的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于angular – 无法解析AuthenticationService的所有参数:([object Object],?,[object Object])、iphone – NSObject和UIViewController有什么区别、iphone – Objective C Bezier Curve ReShaping、iphone – Objective C中方法的多个部分的相关知识,请在本站寻找。
本文标签: