Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I am trying to use a delegate method in my simple iPhone application but I got an error.
If there are any examples code; pls send me a link or code.
When using delegates there are a few things to take care of.
For example, say you have a class MyController and you want it to be a UITextField's delegate. Put the delegate protocol name in the class's interface:
#interface MyController : NSObject <UITextFieldDelegate>
Then, implement the delegate methods in the UITextFieldDelegate docs (the docs say "All of the methods of this protocol are optional." so you can choose which you want):
#implementation MyController
...
- (BOOL)textFieldShouldReturn:(UITextField *)textField
// do something
}
...
#end
Then finally, set yourself as the delegate:
myTextField.delegate = self;
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Good night!
Should I use the method - (void) dealloc in file ViewController.m for outlets (where #synthesize is announced at the beginning of the file) that do not have properties retained?
In ARC, you do not need to implement dealloc other than to release resources managed outside of ARC (retained properties are managed by ARC). If you have a property that managed outside of ARC (say a malloced object), you need to free it in the dealloc method (preferably by setting it to nil and handling the freeing in the setter).
If you do implement dealloc, do not call super as you do when not using ARC.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to have the ability to allow the user to fill out a profile, almost like the notes app and then when they are done it adds it to the UITableViewCell and displays certain parts of what they filled out on the Cell..Then they can obviously repeat this action..
I am not sure where to look for a tutorial on this or what this may be called, anyone have any suggestions?
Five simple steps :
1)Design how form is gonna look like and your tableview.
2)Make the form using a sample UIviewcontroller layout your components using xib or
storyboard
3) Embed your UIViewcontroller designed in step 2 into a UINavigationViewController
This helps you to transition from your form to UITableView
4) Design your UITableViewController and put a back button on UINavigationBar to allow user to go to previous view controller.
5) Connect UIViewController to UITableViewController
-(void)submitButtonPressed:(id)sender{
UITableViewController *tvc = [[UITableViewController alloc] initWithNib:#"your view controller name"];
// pass data to UITableViewController
tvc.userdata = self.userdata;
[self.navigationController pushviewController:tvc];
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have problem about accessing class, and i ve been looking for solution, couldnt figured out yet.
I have 3 classes:
1 - ViewController
2 - XmlParser
3 - AllDeals,
When i open app, ViewController uses XmlParses class, and XmlParser class parses xml file and stores information into NSMutableArray in the XmlParser Class.
I would like to access that NSMutableArray(in XmlParser class) and all information that it stored already from AllDeals class. I cannot split up Xml file again. it s taking too much time.
When i tried to access nothing comes. I have tried many things.
How am i gonna point or access that class or NSMutableArray...
Thank you for your helps.
Have you tried to use shared instance of XmlParser Class ? If Not then make shared instance whenever you want to use this class and access that NSMutableArray with the help of XmlParser Class shared instance.
if you're aware about the delegates then you can pass values over delegate at the success of your parsing else create one NSMutableArray into your 1-ViewController globally and take advantage of it by passing the parent of viewController to XmlParser then you'll have filled NSMutableArray of your desired output and access it further more.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
passing response data from one class to another class
//i want to pass "reside:15" to another View controller.
2013-08-16 14:29:57.273 blabby[1432:1a603] Login response:{"response":"success","resid":15}
add an class
Constant.h
in constant.h
take an string like
NSString *str;
import constant class into your class and than str =your response data;
and use it into another class.
This is an NSDictionary. As with any NSObject, you can make it a property of source view controller and access it in another view controller.
Read it in detail: Coordination between View Controllers.
create a dictionary in the view controller you want to hold that data,while pushing that view controller you can take that data and use it.It is called as design patterns.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have UITextField in secondViewController and a button in same view.
I want to get that UITextField text as a string to firstViewController.
Here my code.
SecondViewController.m
-(void)backToFirstView
{
NSString *str=disTxtFld.text;
FirstView *firstView=[[FirstView alloc]init];
firstView.discountStr=str;
[self.navigationController popViewControllerAnimated:YES];
}
FirstViewController.h
#property (nonatomic,strong) NSString *disStr;
FirstViewController.m
#synthesize disStr;
-(void)viewWillAppear:(BOOL)animated
{
NSLog(#"discount:%#",disStr);
}
When i`am trying to print that string in first view..it showing null value..
any suggestions...
The easiest way to do that is by using delegates. Please take a look here:
http://krodev.wordpress.com/2012/10/08/objective-c-delegates/
It's a step by step guide how to define and implement delegate.
Delegates are used to do just that what you are looking.
make a function in 1st-viewController
-(void)setStringFromSecondView:(NSStirng *)_value{
my_String=[NSString stringwithFormate:#"%#",_value];
}
and add this in header file
-(void)setStringFromSecondView:(NSStirng *)_value;
Now add a delegate variable in secondViewController
{
id delegateOfPrevious;
}
-(void)setDelegate:(id)_delegate{
delegateOfPrevious=_delegate
}
Now before Pushing Second View Controller in First viewController you have to set the delegate of FirstView Like this
secondViewController *secondView=[[secondViewController alloc] init....];
secondView.setDelegate=self;
...........
Now every Thing is set. you are one step away from success:
before popping the SecondViewController you can call this function in second view controller and it will set the value in first view controller.
[delegateOfPrevious setStringFromSecondView:textView.txt];
Do not forget to include firstViewController.h in SecondViewController.
I did this a day before for my own project and it is working fine.
Best way: Use an unwind segue in your storyboard to get back to the previous VC and pass the data along. For more info on this, watch the Storyboards WWDC session from 2012.
Other way: Use the delegate pattern. Create a protocol in your SecondViewController class called SecondViewControllerDelegate. Give it methods like "secondViewControllerDidFinish:" and "secondViewControllerDidCancel:". Have FirstViewController conform to that protocol and provide implementations for those methods. In those implementations, make sure the presented SecondViewController is dismissed. In the SecondViewController, create a delegate property of type id.
When FirstViewController presents SecondViewController, have it set itself as the SecondViewController's delegate. When SecondViewController completes whatever work that needs to be done, have them call the delegate methods and pass in the relevant data.
one best approach is declare your nsstring as global in app delegate.h synthesize it
fill it with data in second view controller then try to acess this nsstring in first view controller.