我想在我的UITextField中檢索輸入的數據並將其分配給參數。我試圖指定標籤的文本框,但標籤全部變成0檢索UITableView中的UITextField數據
代碼:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * defaultCellId = @"DefaultCell";
static NSString * fieldCellId = @"FieldCell";
static NSString * pictureCellId = @"PictureCell";
DefaultCell *defaultCell = [_tableView dequeueReusableCellWithIdentifier:defaultCellId];
FieldCell *fieldCell = [_tableView dequeueReusableCellWithIdentifier:fieldCellId];
PictureCell *pictureCell = [_tableView dequeueReusableCellWithIdentifier:pictureCellId];
if (indexPath.section == 1) {
if (fieldCell == nil) {
fieldCell = [[FieldCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:fieldCellId];
}
fieldCell.field.tag = indexPath.row + 1; //**THIS LINE**
if (indexPath.row == 0)
fieldCell.label.text = @"Namn";
if (indexPath.row == 1)
fieldCell.label.text = @"E-post";
if (indexPath.row == 2)
fieldCell.label.text = @"Telefon";
return fieldCell;
} else if (indexPath.section == 2) {
if (defaultCell == nil) {
defaultCell = [[DefaultCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:defaultCellId];
}
defaultCell.label.text = @"Plats";
return defaultCell;
} else if(indexPath.section == 3) {
if (fieldCell == nil) {
fieldCell = [[FieldCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:fieldCellId];
}
if(indexPath.row == 0)
fieldCell.label.text = @"Titel";
if(indexPath.row == 1)
fieldCell.label.text = @"Text";
return fieldCell;
} else if(indexPath.section == 4) {
if (pictureCell == nil) {
pictureCell = [[PictureCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:pictureCellId];
}
pictureCell.label.text = @"Bild";
return pictureCell;
} else {
if (defaultCell == nil) {
defaultCell = [[DefaultCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:defaultCellId];
}
defaultCell.label.text = @"Lägg upp annons";
return defaultCell;
}
}
It's像這樣的textFieldDidEndEditing方法我想要的。
- (void)textFieldDidEndEditing:(UITextField *)textField {
if(textField.tag == 1)
NSString *title = textField.text;
if(textField.tag == 2)
NSString *phone == textField.text;
}
感謝幫助,謝謝。
謝謝,我會看看! – 2013-03-25 13:50:08