0

Apple から採用した Reachability クラスがあります。私の問題は、Apple に示されている ReachabilityAppDelegate ではなく、ListViewController に到達可能性検出を実装することです。私の問題:

  1. (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath と到達可能性検出で呼び出しメソッドをリンクしたい

  2. セルが接続されていないことが検出された場合はセルを無効にし、接続されている場合はセルを有効にしようとしてい
    ます

これは、viewDidLoad でコーディングされています。

   [[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object: nil];

到達可能性は次のように変更されました。

-(void) reachabilityChanged: (NSNotification* )note{
  Reachability* curReach = [note object];
  NSParameterAssert([curReach isKindOfClass:[Reachability class]]);
  [self updateInterfaceWithReachability: curReach];
}

UITableViewCells の無効化を実装するにはどうすればよいですか

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
  • 上記の方法でこれをコーディングしたことに注意してください。

    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");
    

    }

4

1 に答える 1

0

このようにコーディングBOOL _isOffline して、クラスとupdateInterfaceWithReachability:メソッドにインスタンス変数を追加できます

- (void)updateInterfaceWithReachability:(Reachability* )curReach
{
    if(curReach == XXXXNotReachable)
    {
        //your code
        _isOffline = YES;
    }
    else
    {
        _isOffline = NO;
    }
    [_tableView reloadData];
}

あなたの-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

セルを処理するコードを追加する必要があります。

if(_isOffline)
{
    cell.userInteractionEnabled = NO;
}
else
{
    cell.userInteractionEnabled = YES;
}
于 2013-01-23T06:41:47.730 に答える