У меня есть два tableViewControllers
, второй tableViewController tableViewCell имеет textField
и imageView
, как я могу получить данные из этого textfield
, когда я нажимаю navigationBarBackButton
(Я хочу, чтобы хранить эти данные в первом tableViewController
).Как вернуть данные текстового поля из tableViewCell в объекте c?
// code from second tableViewController...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cellID"];
cell.textLabel.text = @"SIM Name";
cell.detailTextLabel.text = @"AirTel";
cell.imageView.image = [UIImage imageNamed:@"Star2.png"];
return cell;
}
TableViewCell1 *cell1 = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
cell1.nameTextField.delegate = self;
if (indexPath.row == 1) {
NSArray *cell1XibRef = [[NSBundle mainBundle]loadNibNamed:@"TableViewCell1" owner:self options:nil];
cell1 = [cell1XibRef objectAtIndex:0];
cell1.imageView.image = [UIImage imageNamed:@"Con.png"];
self.nameString = cell1.nameTextField.text;
return cell1;
}
return nil;
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{
//Whenever people start editing your textfield
self.nameString = textField.text;
NSLog(@"%@", self.nameString);
}
Использования делегату шаблона. – Sunny
Вы можете использовать метод делегата или просто использовать NSUserdefaults. –
вы можете использовать [NSNotificationCenter] (https://developer.apple.com/reference/foundation/nsnotificationcenter) и создать событие для отправки возвращаемого значения. –