我的應用程序在表格單元格內有一個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