Like my question states. I want to have a textField and have a user type something in and press a button and it shows as a label on different view? What would I use to do. Could you give an example in code form. Plus it is going to be like 28 different TextFields?
Set a delegate for your text field. The textFieldDidEndEditing: method of the UITextFieldDelegate protocol then allows you to intercept the event that occurs once the text field has finished editing.
Your implementation of textFieldDidEndEditing: can then instantiate a UILabel (or some other type of view) that contains the text that the user input into the text field.
-(IBAction)clickButton:(id)sender{
if (!createViewController) {
createViewController = [[CreateViewController alloc] initWithNibName:#"CreateViewController" bundle:nil];
}
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backBarButtonItem;
[backBarButtonItem release];
[self.navigationController pushViewController:createViewController animated:YES];
}
and pass yourTextfield.text to CreateViewController and assign to yourLabel.text
I think it will be helpful to you.
Related
I would like to display ABPersonViewController as a modal instead of pushing it on the navigation stack. I've got this working but to keep a done button present I've had to use an NSTimer to add the button every 0.25 seconds because the done button may be removed when the view appears and is always removed when the app enters the forground. This is a pretty lame hack so I'm wondering if anyone has a better idea :)
I made a subclass of ABPersonViewController that adds the done button and starts the timer on view did load and invalidates it when the view is deallocated.
Here is what my code looks like to show the modal:
- (IBAction)showContactModal:(id)sender{
CNABPersonViewController *personViewController = [[CNABPersonViewController alloc] init];
personViewController.displayedPerson = self.contact.record;
personViewController.addressBook = [[CNAddressBookManager sharedManager] addressBook];
personViewController.viewDelegate = self;
personViewController.shouldShowLinkedPeople = YES;
UINavigationController *navigationController =
[[UINavigationController alloc] initWithRootViewController:personViewController];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navigationController animated:YES completion:nil];
}
I had success in doing it like this. Insert this line to add a button to the navigation bar:
personViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:#"Test" style:UIBarButtonItemStylePlain target:self action:#selector(_yourAddressBookAction)];
If this does not solve your problem, please show us the code that you had the issue with.
This is driving me insane! (ios 5+, ARC)
Pretty simple concept here:
I have a UIView with an embedded UITableView, when clicking on a specific cell, I have iOS launch a modalview with a segue.
This modalview, is a UIView with an Embedded UITableView in it, filled with names from a data source. You can choose multiple items in this view (using cellaccessory: checkmark)
The Goal
Get some sort of "Done" button to show up
Ok, so after much running around, I am to understand that Modal windows do not, in fact, allow navigationController items. No toolbars, no Navigationbars by default.
Ok, so I'll create my own.
- (void)viewDidLoad
{
[super viewDidLoad];
NSInteger tbHeight = 50;
UIToolbar *tb = [[UIToolbar alloc] initWithFrame:CGRectMake(0, (self.view.frame.size.height - tbHeight), self.view.frame.size.width, tbHeight)];
tb.translucent = YES;
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStyleBordered target:self action:#selector(doneAction:)];
NSArray *barButton = [[NSArray alloc] initWithObjects:flexibleSpace,doneButton,nil];
[tb setItems:barButton];
[self.view addSubview:tb];
barButton = nil;
//....
}
Simple enough right?
Well, the toolbar does show up, for sure. BUT, it doesnt stick to the bottom like its supposed to. In fact, when you scroll the embedded tableview up and down, the UIToolbar goes with it, almost like its stuck on the tablevie somehow.
Ive been looking for hours for solutions, I've come across nothing. Wondering if anybody here has any ideas?
If you need more information, please by all means, enquire :)
It's strange that your toolbar is scrolling with the table if it's a UIViewController subclass, unless you've assigned a UITableView to self.view or something... But since it is, this is what I do when adding a fixed item to a table view:
-(void) scrollViewDidScroll:(UIScrollView *)scrollView {
tb.frame = CGRectMake(0, self.view.bounds.size.height-tb.bounds.size.height+scrollView.contentOffset.y, self.view.bounds.size.width, tb.bounds.size.height);
}
I'm currently displaying a PDF file using the Quick Look framework on an iPad via the Modal View Controller. Works great. My problem is that since I'm displaying a PDF file the Quick Look preview is automatically adding a "Print" button. What I would like to do is replace the "Print" button with a custom "Email" button. Is this something that can be done? At first pass I thought this was going to be a somewhat trivial thing to do but at this point I'm really struggling with it. Any help would be greatly appreciated.
Thanks,
Brett
Since QLPreviewController is a subclass of UIViewController, you can take advantage of -[UIViewController setToolbarItems:] to customize the toolbar.
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:#selector(emailPDF)];
NSArray *items = [NSArray arrayWithObject:item];
[previewController setToolbarItems:items animated:NO];
[[self navigationController] presentModalViewController:previewController animated:YES];
Now when the user taps the "reply" icon in the toolbar, your implementation of -emailPDF will get called.
you can create a subclass of QLPreviewController like MyQLPreviewController
Then in viewWillAppear:(BOOL)animated (IMPORTANT!!)
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UIBarButtonItem *rightRatain = self.navigationItem.rightBarButtonItem;
UIBarButtonItem *email = ...;
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:right, email, nil];
[email release];
}
I want to ask a question about the iPhone application. I create the UINavigationController programmatically. And I use the UITableView to do the following thing. However, I don't know how to change the text of the text in the back button (see below, in this case is 'Plays') in code level? Thank you very much.
alt text http://www.freeimagehosting.net/image.php?02730817e4.png
Link: http://www.freeimagehosting.net/image.php?02730817e4.png
To customize the back button you modify the view controller you are going back to. So you can either set the title for your "Plays" view controller:
- (void)viewDidLoad {
// ...
[self setTitle:#"Whatever"];
}
Or access the back button item:
- (void)viewDidLoad {
// ...
// target/action must be nil
self.navigationItem.backBarButtonItem =
[[[UIBarButtonItem alloc] initWithTitle:#"Whatever"
style:UIBarButtonItemStyleBordered
target:nil action:nil] autorelease];
}
You have to actually change the text of the back button before pushing the new view controller onto the stack.Otherwise the back button text will not be displayed.
put this in you viewDidLoad, and i think you will get what you need.
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"yourTitle"
style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backBarButtonItem;
[backBarButtonItem release];
// Original //
I want to call this guy
-(void)addFavorite:(NSString *)favoriteToAdd
at, #selector here
action:#selector([addFavorite favoriteToAdd:#"string"])];
But I keep getting syntax error no matter which way I write it.
Can someone point out the appropriate way to call this function? When it had no parameter and was "addFavorite," it worked fine.
// Update //
I apologize for not being more specific. This is an iphone application. I have a view with a button, when the button is pressed, an NSString is grabbed and passed to addFavorite (function above). I get syntax errors when attempting to add a parameter to addFavorite.
I want to call the following addFavorite
-(void)addFavorite:(NSString *)favoriteToAdd
Something like this
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:#selector([addFavorite: favoriteToAdd:#"testString"])];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
error: Expected ':' before '[' token
[obj action:#selector(addFavorite:) withObject:#"string"]
Edit: can't spell today :)
One of the methods for calling selector on button click:
[buttonObj target:self action:#selector(addFavoriteClick)]`
You'll then have to PULL the string in addFavoriteClick from where it's defined and pass it into addFavorite:
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:#selector(addFavoriteClick:)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
This method will be called once the button got tapped
In the button click, pass the string which should be added as a parameter as follows
-(void)addFavoriteClick:(UIButton*)sender
{
NSString *str=#"stringtobeadded";
[self addFavorite :str];
}
This will help you