我的应用程序在表格单元格内有一个UITextField。表格单元也是在表格委托类的TableController类中构建的。 TableController是ViewController类的一个实例变量。iPhone SDK:如何从TableCell中的TextField向viewController发送消息?
我想要做的是当用户触摸TextField内部时,向ViewController实例发送消息。
这是从TableController剪断代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = @"test";
UITextField *textField = [[[UITextField alloc] initWithFrame:CGRectMake(1.0, 5.0, 120.0, 25.0)] autorelease];
textField.text = @"test 2";
[textField addTarget:self action:@selector(editingStarted) forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = textField;
return cell;
}
的第一个问题是,TableControllers方法editingStarted得到从来没有所谓。下一个有趣的部分是将消息发送到父级ViewController类。
感谢您的回复。我会试试这个。非常感谢! – dan