2015-09-22 91 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 –