Ios 从自定义UITableViewCell访问uitextFields文本
我正在尝试从自定义单元格中的Ios 从自定义UITableViewCell访问uitextFields文本,ios,objective-c,uitableview,custom-cell,Ios,Objective C,Uitableview,Custom Cell,我正在尝试从自定义单元格中的UItextField获取文本。我试着创建一个协议 @class customCellClass @protocol CustomCellDelegate -(void)passText:(CustomCell *)customCell withText:(NSString *)text; @end ... @interface @property (nonatomic, weak) id<CustomCellDelegate> delegate;
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…
有人能解释一下为什么它不起作用,并帮我找出一个有效的方法来获取文本字段文本
CustomCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
然后你可以从单元格中访问
textField.text
。很简单,只要在textField发生变化时做你想做的事情。我有多个textField。我如何区分1和其他文本字段?你应该能够从customCell
中获取indexath。你的意思是:customCellClass*cell=(customCellClass*)textField.superview.superview.superview;
我没有使用didSelectRow…
didtextField
嵌入到单元格中吗?是的,`textField是链接的,为什么不使用cell.myTextField
来访问值?我如何获取cell
?(我需要它在cellForRow…
CustomCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];