开发者

Objective C Simple If Success

Hey everybody, whats the best way to apply the 'if success' method? I'm trying this, but no luck.

BOOL success = false;

success = [self.view addSubview:carregandoView];
carregandoView.backgroundColor = [UIColor clearColor];
carregandoView.center = self.view.center;

if (!success)
{

 //stuff
}

Thanks for any开发者_StackOverflow社区 reply!


First of all, addSubview: doesn't return anything. Secondly, you can test if the subview has already been added like this:

if (carregandoView.superview != self.view)
    // do something

Thirdly, you can add a view to a superview only once (that is, sending [self.view addSubview: carregandoView] multiple times doesn't do anything besides bringing the subview to front), and you can use this trick to ensure the subview remains above its siblings.


That seems to be the correct syntax.

Have you tried NSLog-ging/debugging and inspecting the value of success? See related link here.

Also, it might be the case that

[self.view addSubview:carregandoView]

doesn't seem to return any value (is it a void function?)


You can only use this type of coding style on methods that return a value, and a value that makes sense as a BOOLEAN. addSubView does neither. You need to find some other method, function, property or variable that tells you if what you consider to be a success is true.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜