开发者

Request for member 'uitextfield' in something not a structure or union?

开发者 https://www.devze.com 2023-03-04 20:00 出处:网络
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.

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;
    开发者_JS百科}
    return YES;
}

..........


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号