2011-07-22 44 views
0

在我的應用程序中,我有一個表格視圖,用戶可以在該表格視圖中添加和刪除單元格。當用戶點擊他們創建的單元格時,它會被導航控制器推到新視圖。在這個新視圖中,我有大約8-10個用戶可以編輯的TextField。我的問題是,如何讓viewcontroller將用戶輸入的數據保存到單元格中。我已經得到它來保存,但問題是,當我在一個單元格中輸入數據時,它會將其添加到每個其他單元格,因爲每個單元格都會進入相同的視圖。如何保存每個創建的單元格的數據?將數據保存在表格視圖中單元格視圖

回答

1

我希望這個代碼幫助您 這個代碼不保存數據,這是選擇的表單元格中顯示的每個細節重新編碼,詳細查看錶.m文件

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

if(self.dvController == nil){ 
    DetailsViewController *viewControoler = [[DetailsViewController alloc]initWithNibName:@"detailsViewController" bundle:[NSBundle mainBundle]]; 
    self.dvController = viewControoler; 
    [viewControoler release]; 
} 

DocumentNavController *docObjNew = [appdelegate.noteArray objectAtIndex:indexPath.row]; 

[docObjNew hydrateDetailViewData]; 
// 
dvcontroller.noteObj = docObjNew; //noteobj reference from in DetailsViewController.m file DocumentNavController *noteObj; 

dvcontroller.currentindex = indexPath.row; 


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

self.dvController.title = [docObjNew noteTitle]; 
[self.dvController.noteTitelFiled setText:[docObjNew noteTitle]]; 
[self.dvController.notediscView setText:[docObjNew noteDisc]]; 



} 
在表視圖

查看

.h文件中

@interface DocumentTableViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> { 

UITableView *documenttableView; 

evernoteAppDelegate *appdelegate; 
UINavigationController *navControll; 
DetailsViewController *dvcontroller; 
DocumentNavController *docNavContro; 

//NSIndexPath *selectIndexPath; 


} 

@property (nonatomic, retain)DetailsViewController *dvController; 
@property (nonatomic, retain)DocumentNavController *docNavContro; 
@property (nonatomic, retain)UITableView *documenttableView; 
在DetailsViewController.h

文件

UITextField *noteTitelFiled; 
UITextView *notediscView; 

DocumentNavController *noteObj; 

@property (nonatomic, retain)IBOutlet UITextField *noteTitelFiled; 
@property (nonatomic, retain)IBOutlet UITextView *notediscView; 
@property (nonatomic, retain)DocumentNavController *noteObj; 
相關問題