2016-09-09 57 views
0

我的didSelectRowAtIndexPath方法未調用。我重裝表和它的裝載,並也被稱爲talbeViewdidSelectRowAtIndexPath未調用觸摸

這裏是我的tableview的所有方法的所有方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSString *s = (NSString *) [app.Glb.arrayRoomList objectAtIndex:indexPath.row]; 

    NSString *cellIdentifire = @"CellRoomList"; 
    CellRoomList *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifire]; 
    if(cell == nil) 
    { 
     cell = (CellRoomList*)[[[NSBundle mainBundle] loadNibNamed:@"CellRoomList" owner:self options:nil] objectAtIndex:0]; 
    } 

    cell.lblRoomName.text = s; 

    return cell; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

    return [app.Glb.arrayRoomList count]; 

} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

    NSString *userName = (NSString *) [app.Glb.arrayRoomList objectAtIndex:indexPath.row]; 
    NSLog(@"userName :---- %@",userName); 
    ViewController *chatController = [[ViewController alloc] init]; 
    chatController.chatWithUser = userName; 
    [self.navigationController pushViewController:chatController animated:YES]; 
} 

我讀了堆了一些問題,但不能得到答案。

,如果我長觸摸比細胞細胞的顏色變化,但不叫didSelectRowAtIndexPath

爲什麼它不叫?

這裏是快:

enter image description here

+0

是否已經設置的tableView委託你的viewController,'tableView.delegate =自我;' –

+0

是的,我加入它的廈門國際銀行,這就是爲什麼我的其他方法稱爲 – Kabali

+0

您可以檢查用戶名,你在打印的NSLog它? – Vickyexpert

回答

1

我曾經遇到這個問題很多次。

請採取以下幾點護理

  1. 確保您的細胞不具有任何類型的觸摸/輕敲姿勢的其內容
  2. 確保你的觀點不具有任何觸摸/輕敲姿勢適用
  3. 確保你沒有任何視圖或表格視圖類別(擴展名)有任何觸摸/輕拍手勢[這是更重要的,因爲我們通常不期望]
  4. 檢查是否有任何第三方誰觸摸/輕拍手勢

最常見的原因是視圖中的手勢,以防止表觸及單元格。

+0

是thx這就是概率,即時添加手勢來關閉視圖水龍頭上的鍵盤,這使得在這裏的概率。 – Kabali

0

當你告訴你得到的用戶名,這意味着你的方法被調用,但不是重定向到另一個屏幕,因爲你在錯誤的方式,從而改變引發視圖控制器它由下面,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

    NSString *userName = (NSString *) [app.Glb.arrayRoomList objectAtIndex:indexPath.row]; 
    NSLog(@"userName :---- %@",userName); 

    ViewController *chatController = [[ViewController alloc] initWithNibName:@"ViewControllerId" bundle:nil]; 

    chatController.chatWithUser = userName; 
    [self.navigationController pushViewController:chatController animated:YES]; 
} 
+0

它呼籲長按。 – Kabali

+0

它只會呼籲一下,因爲我們有實現didselect方法內部邏輯並不像日誌壓的手勢,可能是第一次有時需要,但它應該只在觸摸任何行 – Vickyexpert

-1

你在你的AppDelegate.m中添加了導航控制器?

- (BOOL)application:(UIApplication *)application 
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ 

     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

     self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" 
                bundle:nil]; 
    UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:self.viewController]; 
     self.window.rootViewController = navigation; 
    [self.window makeKeyAndVisible]; 
return YES; 
    } 

OR

選擇您的視圖控制器去編輯 - > EmbedIn->導航控制器。這會爲您的storyBorad添加一個導航控制器。

+0

如何它關係到didSelectRowAtIndexPath方法工作? – haresh

0

enter image description here

檢查是否選擇設置爲單一選擇!

+0

是它被選中...... – Kabali

2

單元格中可能存在其他視圖,可能會攔截觸摸事件。確保將NO設置爲屬性userInteractionEnabled以獲取視圖。

+0

是userInteractionEnabled是使 – Kabali

+0

沒有工作...... – Kabali

+0

禁用的觀點(的UILabel ..)在您的自定義單元格,並檢查錶行選擇。 – Rajesh73