I have Reachability class that I adopted from Apple. My problem is implementing my reachability detection in my ListViewController rather than in the ReachabilityAppDelegate shown in Apple. My problems:
-
I want to link the calling method in the (UITableViewCell *)tableView:(UITableView
*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath and the reachability detection -
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:
[[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
-(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 _isOfflinein the class and in your
updateInterfaceWithReachability:methodin your
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPathyou should add your code to deal with the cell , may be