我有一个初始的 tableviewcontroller 正在执行可达性检查。这在 中没有问题viewDidLoad
,但是我想知道重试连接直到它通过的正确方法。我的实现文件中的相关代码如下,如果连接断开,我尝试插入[self ViewDidLoad]
,但这只是将应用程序设置为循环(返回连接失败NSLog
消息)并且不显示UIAlertView
.
- (void)viewDidLoad
{
[super viewDidLoad];
if(![self connected])
{
// not connected
NSLog(@"The internet is down");
UIAlertView *connectionError = [[UIAlertView alloc] initWithTitle:@"Connection Error" message:@"There is no Internet Connection" delegate:self cancelButtonTitle:@"Retry" otherButtonTitles:nil, nil];
[connectionError show];
[self viewDidLoad];
} else
{
NSLog(@"Internet connection established");
UIButton *btn = [UIButton buttonWithType:UIButtonTypeInfoDark];
[btn addTarget:self action:@selector(infoButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
[self start];
}
}