【发布时间】:2013-01-23 06:28:56
【问题描述】:
我有从 Apple 采用的 Reachability 类。我的问题是在我的 ListViewController 中实现可达性检测,而不是在 Apple 中显示的 ReachabilityAppDelegate 中。我的问题:
我想在(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 和可达性检测
如果他们检测到我的单元未连接,我将尝试禁用它,如果它则启用该单元
已连接
这是在 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");}
【问题讨论】:
-
你可以试试github.com/GlennChiu/GCNetworkReachability 会好一点。
-
谢谢。但我仍然不知道如何在我的项目中实现它。我对目标 c 还很陌生。
-
从网站下载,有一个按钮,上面写着 zip。然后将 2 个文件拖到应用程序项目中并确保正在编译 .m 文件(在构建阶段和编译源下),然后在要添加类型的类中 #import "" 并将其导入
标签: iphone ios objective-c xcode