请求成员“uitextfield”在不是结构或联合的东西中?

发布于 2024-11-06 12:01:13 字数 3212 浏览 1 评论 0原文

此时我发现自己正在解决其他几个问题。我已经学到了很多关于我正在尝试做的事情,但我完全被难住了。

我正在为我想要在我的应用程序上使用的登录编写一个文本字段格式,并且因为苹果没有任何类似于文本字段掩码的东西,所以我决定编写自己的自定义单元格,看起来上面有一个掩码,但是我要做的就是在后台连接文本字段。

然而我遇到了一个问题。我正在尝试调用子类 UITableViewCell 中 UITextField 的 textField:shouldChangeCharactersInRange:replacementString: ,如下面的代码所述。但是,我收到了对成员“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;
}

..........

working through several other problems I have found myself at this point. I have learnt alot about the stuff I am trying to do but this one I am completely stumped on.

I am writing a textfield format for a login I would like to have on my app, and because apple don't have anything that resembling a textfield mask I have decided to write my own custom cell that looks like it has a mask on it but all I will be doing is concatenating textfields in the background.

However I have struck a problem. I am trying to call textField:shouldChangeCharactersInRange:replacementString: of a UITextField in my Subclassed UITableViewCell as outlined in my code below. However Im receiving Request for member 'uitextfield' in something not a structure or union error... any help would be appreciated.

////.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;
}

..........

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盛装女皇 2024-11-13 12:01:13

regFieldDone 不是单元格(表视图单元格)的成员。它是您的类注册设备视图控制器的成员。如果您尝试将 regFieldDone 的委托设置为 self,则将该语句更改为 regFieldDone.delegate = self

编辑:您可以直接从 xib 文件中将所有文本字段的委托设置为 RegisterDeviceViewController (文件所有者)。

您只将 regFieldDone 的委托设置为 self,其他 textField 的委托呢?因此,当您编辑其他文本字段时,将不会调用委托方法。

您应该注意到,在编辑 regFieldDone 时会调用 shouldChangeCharactersInRange... 方法,而在编辑其他文本字段时不会调用。我建议您以编程方式或从 xib 文件将所有 textField 的委托设置为 self。

regFieldDone is not a member of cell (table view cell). Its a member of your class register device view controller. If you are trying to set regFieldDone's delegate to self, then change that statement to regFieldDone.delegate = self

EDIT: You can directly set all text field's delegate to RegisterDeviceViewController (file owner) from the xib file.

You have only set regFieldDone's delegate to self, what about other textField's delegate? So when you edit other textField's, the delegate method will not get called.

You should notice that shouldChangeCharactersInRange... method gets called while editing regFieldDone and doesnt while editing other textField's. I advice you to set all textField's delegate to self, either programatically or from xib file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文