仅显示一个单元格UITableView

时间:2015-09-22 16:55:50

标签: ios objective-c uitableview

该应用程序的工作原理如下,它是一个UITableView,显示所有在同一范围内的信标。然后用户可以选择一个信标。在下一个UITableVi我想要显示他们选择的信标,所有关于信标的信息,其中一个信息是每隔0.2秒改变一次值的RSSI。我将这些信息传递给下一页。

- (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 个答案:

答案 0 :(得分: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];
}

或者你可以移动你的&#34;返回单元格;&#34; to if and put&#34; return nil;&#34;最后,如果你在哪里阻挡外面&#34;返回单元&#34;现在