草庐IT

if-cases

全部标签

kotlin - bool 值的使用?在 if 表达式中

如果我有一个可为空的Booleanb,我可以在Java中进行以下比较:Booleanb=...;if(b!=null&&b){/*Dosomething*/}else{/*Dosomethingelse*/}在Kotlin中,我可以使用!!运算符实现相同的目的:valb:Boolean?=...if(b!=null&&b!!){/*Dosomething*/}else{/*Dosomethingelse*/}但是,!!的使用对我来说有点粗略,绕过了null安全系统。有没有更优雅的方法呢?编辑看来我有点过于简单化了。对于局部变量,如Banthar显示,它确实有效。但是,我的boolb实际

ios - XCode 6 - iOS 8 : programmatically check if view is installed

我在界面构建器中使用类大小,为不同的大小定义略有不同的设计。我的观点之一是未安装特定尺寸。这按预期工作,但现在我想以编程方式能够判断是否安装了该View。无论是否安装,看起来View永远不会为零,而且我看不到任何要检查的isInstalled标志。正确的做法是什么? 最佳答案 这不是一个很好的解决方案,但我还没有找到更好的解决方案:docs声明“仍会创建已卸载View的运行时对象。但是,View和任何相关约束都不会添加到View层次结构中,并且View的superView属性为nil”。因此,对有效superView的测试可以作为一

ios - UICollectionView performBatchUpdates : asserts unexpectedly if view needs layout?

如果我从viewWillAppear:内部、viewDidAppear:内部、这些方法之间或集合的任何时间调用-[UICollectionViewperformBatchUpdates:]View没有被更大的UIViewView层次结构布局,CollectionView将断言:***Terminatingappduetouncaughtexception'NSInternalInconsistencyException',reason:'Invalidupdate:invalidnumberofsections.Thenumberofsectionscontainedinthecoll

iphone - 如何在 if 中比较 NSNumber

如何:if(myNSNumber==1){...}这似乎没有建立对象: 最佳答案 如果myNSNUber是NSNumber,你的代码应该是这样的,if([myNSNumberintValue]==1){...}如果是NSInteger,可以直接和整型字面量比较。因为NSInteger是原始数据类型。if(myNSNumber==1){...}注意:确保您的声明中没有*。你的NSInteger声明应该是这样的,NSIntegermyNSNUmber;//RIGHTNSInteger*myNSNUmber;//WRONG,NSInteg

ios - prepareForSegue : how can I set an if-condition?

这可能是非常新手但是...我在我的Storyboard中的两个ViewControllers之间设置了一个segue,标识符为clickBtn。现在我在我的代码中这样调用它:-(void)prepareForSegue:(UIStoryboardSegue*)seguesender:(id)sender{if([[segueidentifier]isEqualToString:@"clickBtn"]){if(conditionVerified){SecondViewController*controller=(SecondViewController*)segue.destinati

iOS 7 SLComposeViewController : Check if tweet was actually posted?

我目前正在使用SLComposeViewController将用户的分数发布到Twitter或Facebook(取决于他们点击的按钮)。当他们分享时,他们将获得虚拟货币奖励。我面临的问题是它只会告诉我用户是点击发送还是取消。我如何检查推文是否实际发布到推特上?这将有助于解决用户尝试两次提交同一条推文的情况(推特不允许)。这是我现在的代码://Checkifusercansendtweetif([SLComposeViewControllerisAvailableForServiceType:SLServiceTypeTwitter]){SLComposeViewController*t

ios - 原因 - (void)cancelTrackingWithEvent :(UIEvent *)event getting called If I am using MSSlideNavigationController?

我尝试在我的ViewController中使用自定义UIControl。我的自定义类是UIControl的子类,并为我的自定义控件分配实例并通过以下代码添加到我的ViewController的View中CustomControl*customControl=[[CustomControlalloc]initWithFrame:CGRectMake(44,388,235,160)];[self.viewaddSubview:customControl];然后我在CustomControl中实现以下委托(delegate)方法-(BOOL)beginTrackingWithTouch:(U

iOS 解析 SDK : How to check if login is from Facebook or Twitter?

我有一个允许用户登录Facebook或Twitter的应用程序。有一个-(void)logInViewController:(PFLogInViewController)logInControllerdidLogInUser:(PFUser)user管理从PFLogInViewController登录的方法。如何检查用户是否按下了Facebook登录按钮或Twitter登录按钮?我的应用程序中有一些功能需要根据登录类型进行不同的设置。 最佳答案 在logInViewController:didLogInUser:中……检查一下BOO

ios - 核心蓝牙 : Getting error even if data is written into writable characteristics

我正在使用CoreBlueTooth框架写入Peripheral的可写特性之一。我在中央实现“didWriteValueForCharacteristic:错误:”委托(delegate),它总是在错误之下返回我。尽管我已经在我的外围设备上收到了数据。ErrorDomain=CBErrorDomainCode=0"Unknownerror."UserInfo=0x166762e0{NSLocalizedDescription=Unknownerror.}在我的代码中,我的self.data是一个具有3个键和值的NSDictionary。//Central-(void)centralMa

ios - 带有 && 运算符的 If 语句检查第二个值?

如果第一个参数为false/NO&&operator检查第二个参数的if语句/?下面会崩溃吗?NSDictionary*someRemoteData=[rawJsonvalueForKey:@"data"];if([someRemoteDataisKindOfClass:[NSDictionaryclass]]&&someRemoteData.count>0){//..dosomething}请不要简单回答是或否,但请解释原因。 最佳答案 不,在得知答案将是NO后,它不会计算表达式。这称为短路,它是在C、C++、ObjectiveC