通过解决其他几个问题,我发现自己在这一点上。我已经学到了很多关于我正在尝试做的事情,但是这一个我完全陷入了困境。请求成员'uitextfield'的东西不是结构或工会?
我正在为我的应用程序编写一个登录文本字段格式,并且因为苹果没有任何类似于文本字段掩码的内容,所以我决定编写自己的自定义单元格,面具上,但我会做的是在后台连接文本框。
但是我碰到了一个问题。我想在我的Subclassed UITableViewCell中调用textField:shouldChangeCharactersInRange:replacementString:的UITextField,如以下代码所述。然而,我收到请求会员'uitextfield'的东西不是结构或联合的错误...任何帮助,将不胜感激。
////.h
@interface RegisterDeviceViewController : UIViewController <UITableViewDelegate, UITextFieldDelegate> {
RegisterDeviceViewController *registerDeviceViewController;
//UITextFields for the registration cell
UITextField *regFieldOne;
UITextField *regFieldTwo;
UITextField *regFieldThree;
UITextField *regFieldFour;
UITableViewCell *myRegistrationField;
UITableViewCell *mySubmitButton;
}
//UITextFields for the registration cell
@property (nonatomic, retain) IBOutlet UITextField *regFieldOne;
@property (nonatomic, retain) IBOutlet UITextField *regFieldTwo;
@property (nonatomic, retain) IBOutlet UITextField *regFieldThree;
@property (nonatomic, retain) IBOutlet UITextField *regFieldFour;
@property (nonatomic, retain) IBOutlet UITableViewCell *myRegistrationField;
@property (nonatomic, retain) IBOutlet UITableViewCell *mySubmitButton;
@end
/////.m
#import "RegisterDeviceViewController.h"
@implementation RegisterDeviceViewController
//Custom registration cell fields
@synthesize regFieldOne;
@synthesize regFieldTwo;
@synthesize regFieldThree;
@synthesize regFieldFour;
@synthesize myRegistrationField;
@synthesize mySubmitButton;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
self.title = @"Registration";
[super viewDidLoad];
}
//Sets number of sections in the table
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
// Sets the number of rows in each section.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
//Loads both Custom cells into each section
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"mythingy"];
if (cell == nil) {
cell = myRegistrationField;
}
UITableViewCell *cellButton = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"mummy"];
if (cellButton == nil) {
cellButton = mySubmitButton;
}
if (indexPath.section == 0) {
return cell;
cell.regFieldOne.delegate = self; //This is where the error is.
}
return cellButton;
}
//This delegate method is not being called.
//textField:shouldChangeCharactersInRange:replacementString:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
int length = [regFieldOne.text length] ;
if (length >= MAXLENGTH && ![string isEqualToString:@""]) {
regFieldOne.text = [regFieldOne.text substringToIndex:MAXLENGTH];
return NO;
}
return YES;
}
..........
你只是想隐藏输入的字符?如果是这样,看看这个属性:@property(nonatomic,getter = isSecureTextEntry)BOOL secureTextEntry – DavidN 2011-05-11 03:05:30
nope,我只想限制每个UItextfield为5个字符。 – tinhead 2011-05-11 03:08:11