2014-12-24 41 views
-3

我有一個UITableView當你選擇一行時,它會引導你進入所選行的「細節」。但是,第一次點擊該行時,它會進入prepareForSegue方法,而不會呼叫didSelectRowAtIndexPath。當我在詳細信息視圖上按下後退按鈕時,該應用會返回,如果再次選擇該行,該方法將被調用。didSelectRowAtIndexPath不是第一次調用

我是不是使用didDeselectRowAtIndexPath

這個模式將繼續,我不明白爲什麼。當我加載我的數據時,我打電話給[tableview reloadData]

我也試着將self.TagsTableView.allowsMultipleSelection = YES;加到我的viewDidLoad方法中。

這裏是我的代碼:

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.bluetoothManager = [[BlueToothLEManager alloc] init]; 

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadTableView:) name:@"ScanComplete" object:nil]; 


    self.Tags = self.bluetoothManager.Tags; 
    NSLog(@"Fetch Tags: %@", self.Tags); 
} 
... 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    UITableViewCell* cell = [fetchTagsTableView dequeueReusableCellWithIdentifier:@"tagCell"]; 

    if(cell == nil){ 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"tagCell"]; 
    } 

    FetchTag* newTag = [fetchTags objectAtIndex:indexPath.row]; 

    cell.textLabel.text = [NSString stringWithFormat:@"%@ %d", newTag.tagName, indexPath.row]; 
    cell.detailTextLabel.text = [newTag.tagUUID UUIDString]; 

    return cell; 
} 

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    selectedTagFromTable = [fetchTags objectAtIndex:indexPath.row]; 
    [TagsTableView deselectRowAtIndexPath:indexPath animated:YES]; 
} 
... 
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    // Get the new view controller using [segue destinationViewController]. 
    if([[segue identifier] isEqualToString:@"DetailView"]){ 
     TagDetailViewController* ftdvc = [segue destinationViewController]; 
     [ftdvc setSelectedTag:selectedTagFromTable]; 


    } 
    // Pass the selected object to the new view controller. 
} 

-(void)reloadTableView:(NSNotification*)notif{ 
    NSLog(@"Reloading Table View"); 
    NSLog(@"Fetch Tags: %@", self.Tags); 
    [self.TagsTableView reloadData]; 
} 
+1

所以,你希望使用故事板segue自動導航選擇_and_調用'didSelectRowAtIndexPath'?我不確定我會相信這一點。我建議刪除自動segue,而是手動調用segue(或手動執行導航)_in_'didSelectRowAtIndexPath'。 – matt

+0

你甚至使用自定義單元格?您是否預先填充代碼中的其他位置的「fetchTagsTableView」單元格(即UITableViewCell * cell = [fetchTagsTableView dequeueReusableCellWithIdentifier:@「tagCell」];)? –

+0

相關:http://stackoverflow.com/q/18165684/335858 – dasblinkenlight

回答

0

我將不得不把代碼從didSelectRowAtIndexPath方法:到prepareForSegue:而不是嘗試使用發件人參數來識別一個選擇的標籤

相關問題