2011-04-06 62 views
5

我在一個視圖中有一個UITableViewCell和UItableView。點擊UITableView的特定行,它導航到另一個視圖控制器。但我無法導航到其他視圖控制器上單擊UITableViewCell 。我怎樣才能做到這一點??UITableViewCell和UITableView(沒有選擇一行)導航到其他視圖控制器

有關的UITableView我使用這個代碼:

 

- 
-(void)pushView1:(id)sender{ 
    if(edController == nil) 
    edController = [[EditableDetailCell alloc] initWithNibName:@"EditableDetailCell" bundle:[NSBundle mainBundle]]; 
    [self.navigationController pushViewController:edController animated:YES]; 
} 
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    UITableViewCell *tbcel; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
    } 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    tbcel.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

    tbcel.layer.cornerRadius = 15; 
    tbcel.text = aBook.Name; 
    switch(indexPath.section) 
    { 
     case 0: 
      cell.text = aBook.Address; 
      break; 
     case 1: 
      cell.text = aBook.Phone; 
      break; 
     case 2: 
      cell.text = aBook.Purchase; 
    } 
    return cell; 
} 


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(edController == nil) 
    edController = [[EditableDetailCell alloc] initWithNibName:@"EditableDetailCell" bundle:[NSBundle mainBundle]]; 
    [self.navigationController pushViewController:edController animated:YES]; 
}![enter image description here][1] 

我應該做的UITableViewCell?

ist is tableviewcell and below it in block is tableview

+1

UITableViewCell是表視圖的一部分嗎?那麼你爲什麼要分開採取行動 – visakh7 2011-04-06 10:25:15

+0

它的UiTableViewCell不包括在Tableview中,它被單獨插入在View Through接口構建器庫中。 – Ketan 2011-04-06 10:31:19

+0

無論是來自IB還是其他任何東西都無所謂。 UITableViewCell不是爲此目的。請參閱下面的答案。 – Xiao 2011-04-06 10:33:03

回答

1

編輯:

你要推的是不是一個UITableViewCell

這是另一種景觀。

你可以說

YourCustomView *view = [[YourCustomView alloc] init]; 
[self.navigationController pushViewController:view animated:Yes]; 

,但我從來沒有看到任何代碼傳遞到另一個細胞。

單元格用於自定義UITableView的外觀。

Add:

我認爲if語句在這裏沒有用。

你的意思

if(edController == nil){ 
    edController = [[EditableDetailCell alloc] initWithnibName:@"EditableDetailCell" bundle:[NSBundle mainBundle]]; 
    [self.navigationController pushViewController:edController animated:YES]; 
} 

或空視圖將要傳遞的任何方式。

+0

我已經編輯我的查詢PLZ cgeck它再次.. – Ketan 2011-04-06 11:21:15

+0

我想pushview1方法在這裏爲tableviewcell(客戶2)導航它,但不是用這種方法導航 – Ketan 2011-04-06 11:23:15

+0

你是否使它成爲一個IBAction,並將此方法連接到正確的按鈕界面生成器?圖片旁邊的customer2是一個按鈕嗎? – Xiao 2011-04-06 11:27:20

1
(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(「Selected Row %d」, indexPath.row); 
    YourNextViewController *objVC = (YourNextViewController *)[storyboard instantiateViewControllerWithIdentifier:@"ViewControllerIdentifier"]; 
    [self presentViewController: objVC animated:YES completion:nil]; 
} 
相關問題