2011-05-11 61 views
0

通过解决其他几个问题,我发现自己在这一点上。我已经学到了很多关于我正在尝试做的事情,但是这一个我完全陷入了困境。请求成员'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; 
} 

.......... 
+0

你只是想隐藏输入的字符?如果是这样,看看这个属性:@property(nonatomic,getter = isSecureTextEntry)BOOL secureTextEntry – DavidN 2011-05-11 03:05:30

+0

nope,我只想限制每个UItextfield为5个字符。 – tinhead 2011-05-11 03:08:11

回答

2

regFieldDone不是细胞(表视图小区)的成员。它是您的类注册设备视图控制器的成员。如果你正在尝试设置regFieldDone的委托,以自己,然后改变语句regFieldDone.delegate =自

编辑:您可以直接从厦门国际银行文件中设置的所有文本字段的委托,以RegisterDeviceViewController(文件所有者)。

您只将regFieldDone的委托设置为self,那么其他textField的委托呢?所以当你编辑其他textField时,委托方法不会被调用。

您应该注意到在编辑regFieldDone时shouldChangeCharactersInRange ...方法被调用,并且在编辑其他textField时没有被调用。我建议你将所有的textField的委托设置为self,无论是以编程方式还是从xib文件。

+0

是的,我这样做,错误消失。然而textField:shouldChangeCharactersInRange:replacementString:委托方法从来没有使用过......我不知道为什么。 – tinhead 2011-05-11 03:15:58

相关问题