从自定义 UITableViewCell 访问 uitextFields 文本
Access uitextFields text from a custom UITableViewCell
我正在尝试从自定义单元格中的 UItextField
获取文本。我尝试创建一个协议
@class customCellClass
@protocol CustomCellDelegate
-(void)passText:(CustomCell *)customCell withText:(NSString *)text;
@end
...
@interface
@property (nonatomic, weak) id<CustomCellDelegate> delegate;
@end
@interface MainCV<CustomCellDelegate>
@end
@implementation MainVC
@end
- (void)viewDidLoad {
CustomCell *cell = ... allocation and initialization
cell.delegate = self;
}
-(void)passText:(CustomCell *)customCell withText:(NSString *)text
{
}
- (void)viewDidLoad {
CustomCell *cell = [[customCellClass alloc] init];
cell.delegate = self;
}
在另一种方法中,我想这样做:
[self.delegate passText:self withText:self.myTextField.text];
但它不允许我做最后一件事:[self.delegate passText...
。
谁能解释一下为什么它不起作用,并帮助我找出一种获取 textFields 文本的有效方法。
CustomCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
然后您可以从单元格访问 textField.text
。
我正在尝试从自定义单元格中的 UItextField
获取文本。我尝试创建一个协议
@class customCellClass
@protocol CustomCellDelegate
-(void)passText:(CustomCell *)customCell withText:(NSString *)text;
@end
...
@interface
@property (nonatomic, weak) id<CustomCellDelegate> delegate;
@end
@interface MainCV<CustomCellDelegate>
@end
@implementation MainVC
@end
- (void)viewDidLoad {
CustomCell *cell = ... allocation and initialization
cell.delegate = self;
}
-(void)passText:(CustomCell *)customCell withText:(NSString *)text
{
}
- (void)viewDidLoad {
CustomCell *cell = [[customCellClass alloc] init];
cell.delegate = self;
}
在另一种方法中,我想这样做:
[self.delegate passText:self withText:self.myTextField.text];
但它不允许我做最后一件事:[self.delegate passText...
。
谁能解释一下为什么它不起作用,并帮助我找出一种获取 textFields 文本的有效方法。
CustomCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
然后您可以从单元格访问 textField.text
。