2011-06-03 37 views
0

在iPhone應用程序中,我有一個表格視圖,其單元格內有一些數據(UITextField,UITextView)。當你觸摸單元格時,我需要將這些數據(UITextField,UITextView)設置爲另一個視圖中的textfield和textView並打開該視圖。iphone用表格單元格觸摸數據打開新窗口

使用此代碼,它會打開觸摸事件的新觀點上的細胞,但它沒有加載數據 因爲我從這些行預計:

[obsevationListView setTitle:titletxt]; 
[obsevationListView setTxtView:titletxt]; 

希望有人能幫助我用一個簡單的例子。
謝謝...

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

    // NSIndexPath *aIndex = [NSIndexPath indexPathForRow:0 inSection:1]; 
    // return aIndex; //return nil so the cell is not selected 

    NSLog(@"cell is selected %d >> %d",(int)indexPath, indexPath.row); 
    Observation *observer = (Observation *)[observations objectAtIndex:indexPath.row]; 
    NSLog((NSString *)observer.title); 
    ObsevationListView *obsevationListView = [[ObservationViewControllor alloc] 
         initWithNibName:@"ObservationViewControllor" 
         bundle:nil]; 
    NSString *titletxt = [[NSString alloc] initWithFormat:@"Hello, %@!", observer.title]; 

    [obsevationListView setTitle:titletxt]; 
    [obsevationListView setTxtView:titletxt]; 

    // UITextView *textView; 
    // UITextField *messageTitle; 

    [self.navigationController pushViewController:obsevationListView animated:YES]; 

    return indexPath; 
} 

我用didSelectRowAtIndexPath方法方法,但它實際上並沒有工作,我需要用裝載打開新視圖一些細節 例如:我顯示了在表視圖觀察草案的列表,當我點擊一行,我想將觀察草稿加載到編輯視圖的字段中,但我使用相同的窗口用空字段進行新的觀察。 我應該使用編輯視圖的init方法中的條件嗎?有人請指導我在Java中,我可以使用重載的構造函數做到這一點我如何設想在Iphone應用程序中做到這一點?

回答

0

使用

didSelectRowAtIndexPath
代替
willSelectRowAtIndexPath

+0

我用didSelectRowAtIndexPath方法方法,但它沒有工作 – 2011-06-06 04:52:29

0

您應該使用

- (NSIndexPath *)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
+0

迪爾是好吃......但我相信你的意思'did'。 – kevboh 2011-06-03 14:33:00

+0

哈哈...大聲笑。我的錯。 – Legolas 2011-06-03 14:35:19

相關問題