[英]Detecting Reachability
I have Reachability class that I adopted from Apple. 我有从Apple采纳的可达性课程。 My problem is implementing my reachability detection in my ListViewController rather than in the ReachabilityAppDelegate shown in Apple.
我的问题是在ListViewController中而不是在Apple中显示的ReachabilityAppDelegate中实现我的可达性检测。 My problems:
我的问题:
I want to link the calling method in the (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath and the reachability detection 我想在(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath和可达性检测中链接调用方法
I am trying to disable my cell if they detect it is not connected and enable the cell if it 我试图禁用我的单元格(如果他们检测到未连接),并启用该单元格(如果它已连接)
is connected 已连接
This is coded in viewDidLoad: 这是在viewDidLoad中编码的:
[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object: nil];
The reachabilityChanged as below: 可达性更改如下:
-(void) reachabilityChanged: (NSNotification* )note{
Reachability* curReach = [note object];
NSParameterAssert([curReach isKindOfClass:[Reachability class]]);
[self updateInterfaceWithReachability: curReach];
}
How do I implement my disabling of UITableViewCells in 我如何在中实现禁用UITableViewCells
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Take note that I have coded this in the above method: 请注意,我已经在上面的方法中对此进行了编码:
NSInteger row = [indexPath row]; NSString *contentForThisRow = nil; static NSString *MyIdentifier = @"MyIdentifier"; if (tableView == [[self searchDisplayController] searchResultsTableView]) { // Sort search results in alphabetical order NSArray *sorted = [searchResults sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; contentForThisRow = [sorted objectAtIndex:row]; }else { contentForThisRow = [nameArray objectAtIndex:row]; } UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]autorelease]; } // Set Device names into Cells cell.textLabel.text = contentForThisRow; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; NSLog(@"Load cell done");
} }
you can code like this , add an instance var BOOL _isOffline
in the class and in your updateInterfaceWithReachability:
method 您可以这样编写代码,在类和您的
updateInterfaceWithReachability:
方法中添加实例var BOOL _isOffline
- (void)updateInterfaceWithReachability:(Reachability* )curReach
{
if(curReach == XXXXNotReachable)
{
//your code
_isOffline = YES;
}
else
{
_isOffline = NO;
}
[_tableView reloadData];
}
in your -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
在
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
you should add your code to deal with the cell , may be 您应该添加代码来处理单元格,可能是
if(_isOffline)
{
cell.userInteractionEnabled = NO;
}
else
{
cell.userInteractionEnabled = YES;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.