0

I want to label the row just like the way iPhone alarm app label's its alarm name. I don't want a back button. I just want to pass whatever text I input to be passed to the MainViewController.

I am using delegate, but I am not quite sure where to put my delegate code in my ViewController which has my texfield. I have 2 ViewControllers connected with "show" segue. One has table row and another has textfield.

Code below:

second.h (where textfield is)

@protocol LabelNameDelegate <NSObject>
- (void)LabelNameEntered:(NSString*)labelName;
@end

@property(nonatomic, weak) id<LabelNameDelegate> delegate;

second.m

 [self.delegate LabelNameEntered:self.myLabel.text];(not sure where to place it exactly)

first.h

 @interface FirstTableViewController : UITableViewController<LabelNameDelegate>

first.m

  - (void)LabelNameEntered:(NSString*)labelName{
NSLog(@"This is text from secondview: %@", labelName);
}
Vig
  • 1,532
  • 1
  • 12
  • 28
Emma
  • 60
  • 10
  • I think you should save all "alarms" someqhere (nsuserdefauilts or core data), update it in detail controller and in list controller reload data on viewWillAppear. It's if I correctly understood what do you want. – Vladislav Kovalyov Nov 21 '14 at 17:05
  • @VladislavKovalyov If you set up the new alarm on your iphone, you have an option to set the alarm name. I just want to know how this functionality is coded. I have a table row in first viewcontroller and textfield on the second viewcontroller, they are connected with "show" segue. – Emma Nov 21 '14 at 17:11
  • "I am using delegate, but I am not quite sure where to put my delegate code in in my viewcontroller where my textfield is." You can put your delegate methods anywhere. –  Nov 21 '14 at 17:43

3 Answers3

1

If I wanted to accomplish this task, I'd create a delegate protocol in my textfield view controller's .h file, then create methods that my textfield view controller could call to let the delegate - which would be the table view's view controller - know what the user entered in the text field.

Edit: This page should help you figure out how to create your own delegate protocol: How do I create delegates in Objective-C?

Edit: If you tried this and can't get it to work, please post some code so we can help you.

Community
  • 1
  • 1
0

In the second.m implement

- textFieldDidBeginEditing:

So whenever the textField is done editing, you can call the delegate you have

Note I am not sure why you have a label here, shouldn't it be textfield?

[self.delegate LabelNameEntered:self.myLabel.text];
Vig
  • 1,532
  • 1
  • 12
  • 28
0

I placed my delegate code in the following method, it worked perfectly. The following code means, once second viewController is closed, pass following value to the first viewController.

second.m

- (void)viewWillDisappear:(BOOL)animated {
[self.delegate LabelNameEntered:self.myLabel.text];
}
Emma
  • 60
  • 10