Reputation: 932
I'm using a UITableView
with a subclassed prototype cell with a UITextField
. The cell is used 4 times total in 4 sections. This is the code for it:
...
- (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;
}
I want to add the text from each cell to the dataSource
object:
-(IBAction)nextButtonPressed:(id)sender {
...
[[dataSource objectAtIndex:dataSourceIndex] setObject:* forKey:@"Smellnote"];
[[dataSource objectAtIndex:dataSourceIndex] setObject:** forKey:@"Tastenote"];
//etc
…
}
*text from cell 1
**text from cell 2
How can I access the text that I want?
Upvotes: 1
Views: 430
Reputation: 9035
Maybe you're looking at it wrong. Why not make the delegate for the textField be the cell itself, ie, in the Cell's class, set the delegate to File'sOwner or self in the init... method.
Create a reference to the dataSource and pass the dataSource to your cell, along with the @"Key" for your dictionary.
cell.dataSource = self.dictionary;
cell.dataKey = @"Tastenote";
//in cell .m
//textFieldDelegate method...
[self.dataSource setObject:self.cellTextView.text forKey:self.dataKey];
Upvotes: 1