2015-09-22 37 views
0

应用程序就像这样工作,它是一个UITableView,它显示所有位于同一范围内的信标。然后用户可以选择一个信标。在接下来的UITableVi中,我想展示他们选择的信标,所有关于信标的信息,其中一个信息是每隔0.2秒改变一次值的RSSI。我将这些信息传递到下一页。只显示一个单元UITableView

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Tag"]; 

    AXABeacon *beacon = [[AXABeacon alloc] init]; 
    beacon = [self.sortedDevices objectAtIndex:indexPath.row]; 

    if([_beaconSelected.name isEqualToString:beacon.name]) 
    { 
     UILabel *titleLabel = (UILabel *)[cell viewWithTag:1]; 
     UILabel *uuidLabel = (UILabel *)[cell viewWithTag:2]; 
     UILabel *rssiLabel = (UILabel *)[cell viewWithTag:3]; 
     UILabel *majorLabel = (UILabel *)[cell viewWithTag:4]; 
     UILabel *minorLabel = (UILabel *)[cell viewWithTag:5]; 

     titleLabel.text = [NSString stringWithFormat:@"%@", beacon.name]; 
     uuidLabel.text = [NSString stringWithFormat:@"%@", beacon.uuidString]; 
     rssiLabel.text = [NSString stringWithFormat:@"RSSI: %@", [beacon.rssi stringValue]]; 
     minorLabel.text = [NSString stringWithFormat:@"Minor: %@", beacon.minor]; 
     majorLabel.text = [NSString stringWithFormat:@"Major: %@", beacon.major]; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

     uuidLabel.adjustsFontSizeToFitWidth = YES; 
     titleLabel.adjustsFontSizeToFitWidth = YES; 
     cell.accessoryType = UITableViewCellAccessoryNone; 
    } 

    return cell; 
} 

以下是我目前的工作情况。这可行,但问题是这种方法不断搜索信标,当它发现另一个信标它显示一个空单元格。我不想让它显示另一个单元格。我希望它只显示他们选择的灯塔的信息。我该怎么做?

+1

那么,为什么你只有一个项目要显示时使用表格视图? – Wain

+0

为什么只用一个单元格使用表格视图?为什么不使用所需标签的普通视图控制器?为什么这个视图控制器,用来显示一个设备的细节,有多个设备的参考? – rmaddy

+0

我现在面临的问题是,我必须向每个0.2秒显示RSSI值的人员。 RSSI与用户从第一个UITableView选择一个信标并保持不变的情况相同。我希望对象始终更新其信息。 @maddy –

回答

0

如果你真的想使用的UITableView的细节,我会在这个方法中筛选标:

- (void)locationManager:(CLLocationManager*)manager 
    didRangeBeacons:(NSArray*)beacons 
      inRegion:(CLBeaconRegion*)region 
{ 
    [yourMutableArray removeAllObjects]; 
    for (int i = 0; i < [beacons count]; i++) { 
     // Compare major/minor of selected beacon with all beacons 
     // and store detail information only for one specific beacon 
     // to some custom object. Add this object to NSMutableArray 
     // and use it as a data source for table view. 
     NSString *major = [NSString stringWithFormat:@"%@", [(CLBeacon *)[beacons objectAtIndex:i] major]]; 
     NSString *minor = [NSString stringWithFormat:@"%@", [(CLBeacon *)[beacons objectAtIndex:i] minor]]; 
     if ([major isEqualToString:_selectedMajor] && [minor isEqualToString:_selectedMinor]) { 
      FoundBeacon *b = .... 
      [yourMutableArray addObject:b]; 
     } 
    } 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [yourMutableArray count]; 
} 

或者,你可以将你的“回归细胞;”如果阻止并把“返回零”;最后,如果你现在有了“返回细胞”的区域,那么在外面。

+0

你的'numberOfRowsInSection'甚至不会编译。 – rmaddy

+0

谢谢@rmaddy,固定。 –

+0

我没有返回零,我有返回单元格,但我得到这个错误'2015-09-22 19:27:33.858 AXASDK [3870:847430] ***终止应用程序,由于未捕获的异常'NSInternalInconsistencyException',原因:'UITableView (; layer = ; contentOffset:{0,-64} ; contentSize:{320,718}>)无法从其dataSource()中获取单元格“@JosefRysanek –