Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

In objective-c I have an app that when you open one of the textfield it scrolls to that field though I can only manage to do that with one element as when I try and combine multiple into one it doesn't let me. Here is the code of the identifyer:

@property (weak, nonatomic) IBOutlet UITextField *textField;

Though my scrolling is working fine I can't asign two elements to @property (weak, nonatomic) IBOutlet UITextField *textField;

Is there a way to do it and if so how

Here is my scrolling code:

.m:

- (void)textFieldDidBeginEditing:(UITextField *)sender {
    svos = _scrollView.contentOffset;
    CGPoint pt;
    CGRect rc = [sender bounds];
    rc = [sender convertRect:rc toView:_scrollView];
    pt = rc.origin;
    pt.x = 0;
    pt.y -= 60;
    [_scrollView setContentOffset:pt animated:YES];
}

- (IBAction)textFieldShouldReturn:(UITextField *)textField {
    [_scrollView setContentOffset:svos animated:YES];
    [textField resignFirstResponder];
}

.h:

CGPoint svos;
share|improve this question
What you exactly want ?? please elaborate your Question :) – iPatel 1 hour ago
1  
Show the scrolling code and explain what it does wrong because the question doesn't make sense. – Wain 1 hour ago
@Wain have shown the scrolling code – user2568107 34 mins ago

1 Answer

You can't assign a property to more than one outlet at a time. What you need to do is set your view controller as the delegate of both textfields. To do that in interface builder ctrl-drag from each textfield to your view controller and select delegate. If you want to code this instead, create a property for each textfield and assign the delegate properties in viewDidLoad. Like this

@property (nonatomic, weak) IBOutlet UITextField *textField1;
@property (nonatomic, weak) IBOutlet UITextField *textField2;

don't forget to wire them in interface builder and in viewDidLoad,

- (void)viewDidLoad
{
    [super viewDidLoad];

    textField1.delegate = self;
    textField2.delegate = self;
}
share

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.