我正在将子视图(带有来自另一个文件(AutocompleteTable.h 和 .m)的委托的 UITableView)添加到名为 AddViewController 的 ViewController:
AddViewController.h
#import "AutocompleteTable.h"
@property (weak, nonatomic) IBOutlet UITextField *itemName;
AddViewController.m
@interface AddViewController ()
{
AutocompleteTable *autocompleteDelegate;
}
@end
@implementation AddViewController
...
- (void)viewDidLoad
{
[super viewDidLoad];
autocompleteDelegate = [[AutocompleteTable alloc] init];
...
autocompleteTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 88, 320, 120) style:UITableViewStylePlain];
autocompleteTable.delegate = (id)autocompleteDelegate;
autocompleteTable.dataSource = (id)autocompleteDelegate;
...
[self.view addSubview:autocompleteTable];
}
在 AutocompleteTable.m 中,我尝试使用 didSelectRowAtIndexPath 将 AddViewController 的 itemName.text 设置为选定行的文本,但不起作用:
AutocompleteTable.h
#import "AddViewController.h"
AutocompleteTable.m
@interface AutocompleteTable()
{
AddViewController *addController;
}
@end
@implementation AutocompleteTable
...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
addController = [[AddViewController alloc] init];
addController.itemName.text = selectedCell.textLabel.text;
self.hidden = YES;
}
怎么了?