我正在开发应用程序。
我制作了一个自定义的UITableViewCell。
但我无法获得自定义tableviewcell的内容。
例如,这是我的自定义UITableViewCell的图像。
TextEditorCell.h
...
@property (weak, nonatomic) IBOutlet UITextField *textField;
...
AddNewObject.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
_textEditor = [tableView dequeueReusableCellWithIdentifier:@"Text"];
_datePicker = [tableView dequeueReusableCellWithIdentifier:@"Date"];
SwitchCell *_switch = [tableView dequeueReusableCellWithIdentifier:@"Switch"];
// Configure the cell...
if (indexPath.section == 0) {
return _textEditor;
}else if (indexPath.section == 1){
return _datePicker;
}else{
_switch.titleLabel.text = @"Main Countdown";
return _switch;
}
return nil;
}
...
- (IBAction)Done:(id)sender
{
NSLog(@"Text:%@",_textEditor.textField.text);
}
日志
2013-12-27 23:47:58.498 Application[10039:80b] Text:(null)
我写了一句话。
但是log为null。
为什么?
答案 0 :(得分:0)
Cell是一个View,它不应该存储任何数据。我假设您的IBAction
位于自定义单元格类中。因此,如果您想在那里传递参数(即使在同一个类中),您不得不将您的属性设置为strong
:
@property (strong, nonatomic) IBOutlet UITextField *textField;
答案 1 :(得分:0)
我解决了自己的问题。
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
TextEditorCell *cell = (TextEditorCell*)[self.tableView cellForRowAtIndexPath:indexPath];
NSString *text = cell.textField.text;
NSLog(@"Text:%@",text);
我感谢每个回答者!!!