没有互联网连接时禁用按钮

时间:2011-09-02 12:21:02

标签: ios objective-c cocoa-touch internet-connection

如果在iOS中没有连接到网络/互联网时,如何禁用按钮?

2 个答案:

答案 0 :(得分:3)

查看Apple的可访问性代码。

http://developer.apple.com/library/ios/#samplecode/Reachability/Introduction/Intro.html

并像这样使用它:

Reachability *reachabilityInstance = [[Reachability reachabilityForInternetConnection] retain];
[reachabilityInstance startNotifier];
NetworkStatus networkStatus = [reachabilityInstance currentReachabilityStatus];
BOOL connected = (networkStatus==ReachableViaWiFi || networkStatus==ReachableViaWWAN);

答案 1 :(得分:1)

您可以随时隐藏按钮

[button setHidden:YES];