Я создал несколько таблиц с текстовыми полями внутри, как в контактах для iphone,
(вдохновлено примером UICatalog)
все работает, но как я могу программно читать значения этих текстовых полей, я вижу, что у них есть тег, но как я могу читать из них (потому что я не могу использовать IB для этого, так как они были созданы программно для перехода внутри таблицы) (нуб тут!)
спасибо,
Я использую некоторый пример стиля hello world, где я набираю текстовое поле таблицы, затем нажимаю кнопку, и набранный текст переходит на метку,
Этот пример должен в конечном итоге заполнить мою базу данных coredata из текстовых полей таблицы
Как я уже сказал, я preatty noob для этого, так что, пожалуйста, проведите меня через
поэтому, когда пользователь нажимает кнопку Отправить, я получаю текст на метку (и вскоре на coredata)
- (IBAction) submitYourName;{
lblUserTypedName.text = txtUserName.text;
NSLog(@"received");
}
это код моего текстового поля
- (UITextField *)textFieldNormal
{
if (textFieldNormal == nil)
{
CGRect frame = CGRectMake(kLeftMargin, 8.0, kTextFieldWidth, kTextFieldHeight);
textFieldNormal = [[UITextField alloc] initWithFrame:frame];
textFieldNormal.borderStyle = UITextBorderStyleRoundedRect;
textFieldNormal.textColor = [UIColor blackColor];
textFieldNormal.font = [UIFont systemFontOfSize:17.0];
textFieldNormal.placeholder = @"<enter text>";
textFieldNormal.backgroundColor = [UIColor whiteColor];
textFieldNormal.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
textFieldNormal.keyboardType = UIKeyboardTypeDefault; // use the default type input method (entire keyboard)
textFieldNormal.returnKeyType = UIReturnKeyDone;
textFieldNormal.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right
textFieldNormal.tag = kViewTag; // tag this control so we can remove it later for recycled cells
textFieldNormal.delegate = self; // let us be the delegate so we know when the keyboard's "Done" button is pressed
// Add an accessibility label that describes what the text field is for.
[textFieldNormal setAccessibilityLabel:NSLocalizedString(@"NormalTextField", @"")];
}
return textFieldNormal;
}
и это, чтобы показать это текстовое поле в ячейке таблицы
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
static NSString *kCellTextField_ID = @"CellTextField_ID";
cell = [tableView dequeueReusableCellWithIdentifier:kCellTextField_ID];
if (cell == nil)
{
// a new cell needs to be created
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:kCellTextField_ID] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
else
{
// a cell is being recycled, remove the old edit field (if it contains one of our tagged edit fields)
UIView *viewToCheck = nil;
viewToCheck = [cell.contentView viewWithTag:kViewTag];
if (viewToCheck)
[viewToCheck removeFromSuperview];
}
UITextField *textField = [[self.dataSourceArray objectAtIndex: indexPath.section] valueForKey:kViewKey];
[cell.contentView addSubview:textField];
return cell;
}