2012-10-02 51 views
1

我正在使用帶有UITextField的子類原型單元的UITableView。細胞共4次使用4次。這是它的代碼:在UITableViewCell中訪問UITextField

... 
- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
cellTitles = [[NSArray alloc] initWithObjects:@"Smell", @"Taste", @"Suits", @"Notes", nil]; 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
return [cellTitles count]; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
return [cellTitles count]/[cellTitles count]; 
} 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{ 
    return [cellTitles objectAtIndex:section]; 
} 

- (AddInfoCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *cellIdentifier = @"AddInfoCell"; 

AddInfoCell *addInfoCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

if (addInfoCell == nil) { 
    addInfoCell = [[AddInfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
} 
addInfoCell.cellTextView.delegate = self; 

return addInfoCell; 
} 

我想將文本從每個單元格添加到dataSource對象:

-(IBAction)nextButtonPressed:(id)sender { 
... 
[[dataSource objectAtIndex:dataSourceIndex] setObject:* forKey:@"Smellnote"]; 
[[dataSource objectAtIndex:dataSourceIndex] setObject:** forKey:@"Tastenote"]; 
//etc 
… 
} 

*從單元格文本1

**從小區2文本

如何訪問我想要的文本?

回答

1

也許你看錯了。爲什麼不讓textField的委託成爲單元格本身,即在Cell的類中,將委託設置爲File'sOwner或self?在init ...方法中。

創建對dataSource的引用,並將dataSource傳遞給您的單元格以及字典的@「Key」。

cell.dataSource = self.dictionary; 
cell.dataKey = @"Tastenote"; 
//in cell .m 
//textFieldDelegate method... 
[self.dataSource setObject:self.cellTextView.text forKey:self.dataKey]; 
+0

我明白了,謝謝!你能告訴我textFieldDelegate方法在cell.m中的樣子嗎? – ingenspor

相關問題