iPhone TableView with TextFields - next, previous button issue - objective-c

I have a table view which has a good number of cells in it used to create a form. I have created a custom TableViewCell. This cell contains a label and a text field, so for example, each row will look something like this
I also have a custom table cell which contains a label and a text view, looks the same as image above, just cell is larger to allow room for the textview.
Now each of these text fields and text views has a tool bar added, so when text field becomes first responder, a tool bar is shown with the buttons, done, previous and next buttons.
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]initWithTitle:#"Done" style:UIBarButtonItemStyleDone target:self action:#selector(doneWithTextField:)];
UIBarButtonItem *nextButton = [[UIBarButtonItem alloc]initWithTitle:#"Next" style:UIBarButtonItemStyleDone target:self action:#selector(nextTableTextField:)];
UIBarButtonItem *previousButton = [[UIBarButtonItem alloc]initWithTitle:#"Previous" style:UIBarButtonItemStyleDone target:self action:#selector(previousTableTextField:)];
UIToolbar *numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
numberToolbar.barStyle = UIBarStyleBlackTranslucent;
numberToolbar.items = [NSArray arrayWithObjects:
previousButton,
nextButton,
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
doneButton,
nil];
[numberToolbar sizeToFit];
field.inputAccessoryView = numberToolbar;
The issue I am having is, say I have 10 table rows like this, the screen can only show about 5 full rows and a bit of the 6th row. I should add I also have added the code to the text field delegates so that when a text field becomes first responder, screen scrolls to allow the text field to be fully shown. See my older post here for code.
So when screen loads I press the first cell, and click next, works fine, moves onto the 2nd text field in the next cell. Then I hit the next button again, and it goes to the 3rd cell, then 4th, then 5th. Now at this point the problem occurs. When I am on the 5th cell, and I click next, the 6th text field becomes the first responder but the screen does not scroll for some reason. Now the bigger problem is, when I click next again, it does not move onto the 7th text field, as the 7th cell is not in memory yet as it is not visible on the screen. So if I hit next, it won't do anything, text field 6 will remain as the first responder. So I need to scroll down a bit first, so cell 7 is visible before the next button will work and make the next text field the first responder.
It is the same issue when hitting the previous button, if hit previous button and the previous cell is not in screen, then it will not do anything until that cell is visible on the screen.
This has been causing me quite a headache as can't seem to figure out a way around this. Has anyone else had similar problems like this? Is there a good work around to this problem?
Thanks in advance
Edit:
I should also add this makes saving data a problem because say I have a button that when clicked loops through each table cell and saves the data in each field, it will only loop through the table cells that are visible on screen and ignore the rest.

It works for me, I'm using blocks which is fired when "done" button on keyboard pressed to move focus into next text fielded cell:
FRTextFieldTableViewCell *textFieldCell = [tableView_ dequeueReusableCellWithIdentifier:[FRTextFieldTableViewCell reuseIdentifier]];
if(textFieldCell == nil) {
textFieldCell = [[FRTextFieldTableViewCell alloc] initWithStyle:
UITableViewCellStyleDefault reuseIdentifier:[FRTextFieldTableViewCell reuseIdentifier]];
}
[textFieldCell.textField initialize];
textFieldCell.textField.secureTextEntry = (indexPath.row == 3);
__weak FRSignUpViewController *self_ = self;
__weak FRTextFieldTableViewCell *textFieldCell_ = textFieldCell;
if(indexPath.row == 1) {
textFieldCell.textField.placeholder = NSLocalizedString(#"name", #"");
textFieldCell.object = self.regUser.name;
textFieldCell.didChangedValueAction = ^(NSString *object) {
[self_ setName:object];
};
textFieldCell.didEndOnExitAction = ^{
[self_ setName:textFieldCell_.object];
FRTextFieldTableViewCell *nextCell = (FRTextFieldTableViewCell *)[self_.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]];
[nextCell.textField becomeFirstResponder];
};
}
if(indexPath.row == 2) {
textFieldCell.textField.placeholder = NSLocalizedString(#"email", #"");
textFieldCell.didChangedValueAction = ^(NSString *object) {
[self_ setLoginString:object];
};
textFieldCell.didEndOnExitAction = ^{
[self_ setLoginString:textFieldCell_.object];
FRTextFieldTableViewCell *nextCell = (FRTextFieldTableViewCell *)[self_.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:3 inSection:0]];
[nextCell.textField becomeFirstResponder];
};
}
if(indexPath.row == 3) {
textFieldCell.textField.placeholder = NSLocalizedString(#"password", #"");
textFieldCell.didChangedValueAction = ^(NSString *object) {
[self_ setPasswordString:object];
};
textFieldCell.didEndOnExitAction = ^{
[self_ setPasswordString:textFieldCell_.object];
[self_ signUp];
};
}
[textFieldCell reloadData];
return textFieldCell;
BlocksTypedefs:
/* type defenition for blocks, can be used by any app class */
typedef void (^CompletionBlock)(id, NSError *);
typedef void (^SimpleBlock)(void);
typedef void (^InfoBlock)(id);
typedef void (^ConfirmationBlock)(BOOL);
TableViewCell code:
.h file:
#import "FRTableViewCell.h"
#import "BlocksTypedefs.h"
#import "FRTextFieldWithPadding.h"
#interface FRTextFieldTableViewCell : FRTableViewCell <UITextFieldDelegate>
#property (nonatomic, copy) SimpleBlock didEndOnExitAction;
#property (nonatomic, copy) SimpleBlock didEndEditingAction;
#property (nonatomic, copy) InfoBlock didChangedValueAction;
#property (nonatomic, strong) IBOutlet FRTextFieldWithPadding *textField;
#end
.m:
#import "FRTextFieldTableViewCell.h"
#implementation FRTextFieldTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
self.backgroundColor = [UIColor clearColor];
}
- (void)reloadData {
self.textField.text = self.object;
}
- (IBAction)textFieldValueDidChanged:(UITextField *)sender {
self.object = sender.text;
if (self.didChangedValueAction) {
self.didChangedValueAction(self.object);
}
}
- (IBAction)textFieldDidEndOnExit:(UITextField *)sender {
self.object = sender.text;
if (self.didEndOnExitAction) {
self.didEndOnExitAction();
}
}
#pragma mark - UITextFieldDelegate
- (void)textFieldDidEndEditing:(UITextField *)textField {
self.object = textField.text;
if (self.didEndEditingAction) {
self.didEndEditingAction();
}
}
#end

CGRect frame = CGRectMake(0.0, self.view.bounds.size.height, self.view.bounds.size.width, 44.0);
fieldAccessoryView = [[UIToolbar alloc] initWithFrame:frame];
fieldAccessoryView.barStyle = UIBarStyleBlackOpaque;
fieldAccessoryView.tag = 200;
[fieldAccessoryView setBarStyle:UIBarStyleBlack];
UIBarButtonItem *spaceButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(done:)];
UISegmentedControl* segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:NSLocalizedString(#"Previous", #""), NSLocalizedString(#"Next", #""), nil]];
[segmentedControl addTarget:self action:#selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
[segmentedControl setMomentary:YES];
UIBarButtonItem *segmentButton = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[fieldAccessoryView setItems:[NSArray arrayWithObjects:segmentButton, spaceButton, doneButton, nil] animated:NO];
[segmentButton release];
[spaceButton release];
[doneButton release];
[segmentedControl release];

Related

Adding UISearchBar in UINavigationBar with constraints

All,
I want to add UISearchBar to UINavigationbar, I dont dont want to use UISearchController, Just UISearchbar programmatically and it must work in landscape as well.
I tried it is working well in Portrait well, but in Landscape, i have issues in iPhone X width. Can we use Constraints.
Below is the code
CGFloat width = [UIScreen mainScreen].bounds.size.width;
search = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, width - 2 * 44 - 2 * 15, 44)];
search.delegate = self; // search.tintColor = [UIColor redColor];
search.searchBarStyle = UISearchBarStyleMinimal;
search.placeholder = #"Search";
search.translucent = NO;
search.opaque = NO;
search.showsCancelButton = NO;
[search setBackgroundImage:[[UIImage alloc] init]];
//customize textfield inside UISearchBar
#try {
for (id object in [[[search subviews] firstObject] subviews])
{
if (object && [object isKindOfClass:[UITextField class]])
{
UITextField *textFieldObject = (UITextField *)object;
textFieldObject.backgroundColor = [UIColor whiteColor];
textFieldObject.borderStyle = UITextBorderStyleRoundedRect;
textFieldObject.layer.borderColor = (__bridge CGColorRef _Nullable)([brandingObj getValueForKey:navBarTitleColor]);
textFieldObject.layer.borderWidth = 1.0;
break;
}
}
}
#catch (NSException *exception) {
NSLog(#"Error while customizing UISearchBar");
}
#finally {
}
I don't understand why you want to use UISearchDisplayController, its highly configurable and recommended by apple, working with geometry (CGRecr, CGFrame, etc.) to adjust UIKit objects layout could be a pain, use auto layout avoiding UIKits convenience initializers, to adjust later constraints.
Anyway if you want explicitly do with this way, this should work.
#import "ViewController.h"
#interface ViewController ()<UISearchBarDelegate>
#property UISearchBar *searchbar;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_searchbar = [UISearchBar new];
_searchbar.delegate = self;
_searchbar.searchBarStyle = UISearchBarStyleMinimal;
self.navigationItem.titleView = self.searchbar;
// Do any additional setup after loading the view, typically from a nib.
}
Maybe you should need configure appearance , take a look here
Cheers.

Displaying a popover around a UIButton inside UIBarButtonItem

userButtonPressed gets called with the UIButton as parameter, when the userUIBtn gets clicked.
However, I would like to access the UIBarButtonItem instead, in order to display a popover around.
Here is the generateToolbar() method, which generates the user navigation button.
-(void) generateToolbar {
// Initialize the `ButtonFactory`
ButtonFactory *buttonFactory = [[ButtonFactory alloc] init];
// Generate some `UIButton(s)`
UIButton *userUIBtn = [buttonFactory createButtonWithButtonType:ButtonTypeUser];
userUIBtn.frame = CGRectMake(0,0,55,20);
// Add an action to the `UIButton`
[userUIBtn addTarget:self action:#selector(userButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
// Generate an `UIBarButtonItem` with the `UIButton` as basis view
UIBarButtonItem *userBtn = [[UIBarButtonItem alloc] initWithCustomView:userUIBtn];
// Add the `UIBarButtonItem` into the right side of the `navigationItem`
self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects: userBtn, nil];
}
Here is the userButtonPressed() method, which gets triggered by pressing the user button and generates a popover around that button - It is not being called.
- (IBAction) userButtonPressed:(UIBarButtonItem*)sender {
// Initialize the `ButtonFactory`
ButtonFactory *buttonFactory = [[ButtonFactory alloc] init];
// Generate some `UIButton(s)`
UIButton *feedbackUIBtn = [buttonFactory createButtonWithButtonType:ButtonTypeFeedback iconVisibility:YES textVisibility:YES capitalization:NO iconSize:20.0 textSize:20.0];
[feedbackUIBtn addTarget:self action:#selector(feedbackBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
feedbackUIBtn.frame = CGRectMake(0,50,300,50);
// Create a `UIViewController` and add the `UIButtons` as subviews
UIViewController *viewController = [[UIViewController alloc] init];
[viewController.view addSubview:feedbackUIBtn];
// Present the `UIViewController`
viewController.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:viewController animated:YES completion:nil];
// Set up the `UIPopoverPresentationController`
UIPopoverPresentationController *popController = [viewController popoverPresentationController];
popController.permittedArrowDirections = UIPopoverArrowDirectionUp;
popController.barButtonItem = sender;
}
My solution was to edit the action handler in two places, I changed the parameter from UIBarButtonItem to UIButton and changed popController.barButtonItem = sender; to popController.sourceView = sender;.
- (IBAction) userButtonPressed:(UIButton*)sender {
...
popController.sourceView = sender;
...
}

Does it make sense to add ATMHud to tabBarController.view

When i try to add ATMHud to uitableviewcontroller subview it does work but it doesn't disable the scrolling and if the tableview is not on top i can't see the hud view. What i did was added to teh tabBarController.view that works but i want find out if this is a good idea or later on i might have issues with it.
Another question is tabBarController.view frame is that the whole screen or just the bottom part. How come atmhud shows in the middle of the screen?
Thanks in advance!
Yan
============
Found a blog post that shows how to reset self.view and add tableview separately in uitableviewcontroller
UITableViewController and fixed sub views
- (void)viewDidLoad {
[super viewDidLoad];
if (!tableView &&
[self.view isKindOfClass:[UITableView class]]) {
tableView = (UITableView *)self.view;
}
self.view = [[[UIView alloc] initWithFrame:
[UIScreen mainScreen].applicationFrame] autorelease];
self.tableView.frame = self.view.bounds;
self.tableView.contentInset = UIEdgeInsetsMake(44.0, 0.0, 0.0, 0.0);
[self.view addSubview:self.tableView];
UIView *fixedBar = [[UIView alloc] initWithFrame:
CGRectMake(0.0, 0.0, self.view.bounds.size.width, 44.0)];
fixedBar.backgroundColor = [UIColor colorWithRed:
0.0 green:1.0 blue:0.0 alpha:0.7];
[self.view addSubview:fixedBar];
[fixedBar release];
}
After this when add hud to self.view you will be able to disable the tableview on the bottom.
Let me know if this a good way to setup the tableview
The problem with using the tab bar is that the hud is now modal, and the user cannot change the tab.
It sounds like the tableview is not your primary viewm, as it can get "covered up". If its not the primary view, then add the ATMHud to self.view. If the tableView is the same as self.view, then add a new transparent view to it, then add the HUD to that view.
The tabBarController.view is the view that hosts the tabbed views - if you want to see its size (or frame) log it using NSStringFromCGRect(self.tabBarController.frame);
EDIT: I just did a test, the ATMHud DOES block the UI. All I can think of is that you have not inserted it where you need to (at the top of current view's subviews.) I have a demo project where I do this:
hud = [[ATMHud alloc] initWithDelegate:self];
[self.view addSubview:hud.view];
[hud setCaption:#"Howdie"];
[hud setActivity:YES];
[hud show];
[hud hideAfter:5];
A button under the hud is not active - in fact nothing in the view is active (probably the Nav Bar would be live though)
If you want an ARCified and field tested version, you can grab it here
EDIT2: The solution to your problem is below. Note that ATMHud blocks clicks from getting to the table, and the code below stops the scrolling:
- (void)hudWillAppear:(ATMHud *)_hud
{
self.tableView.scrollEnabled = NO;
}
- (void)hudDidDisappear:(ATMHud *)_hud
{
self.tableView.scrollEnabled = YES;
}
Dump the views:
#import <QuartzCore/QuartzCore.h>
#import "UIView+Utilities.h"
#interface UIView (Utilities_Private)
+ (void)appendView:(UIView *)v toStr:(NSMutableString *)str;
#end
#implementation UIView (Utilities_Private)
+ (void)appendView:(UIView *)a toStr:(NSMutableString *)str
{
[str appendFormat:#" %#: frame=%# bounds=%# layerFrame=%# tag=%d userInteraction=%d alpha=%f hidden=%d\n",
NSStringFromClass([a class]),
NSStringFromCGRect(a.frame),
NSStringFromCGRect(a.bounds),
NSStringFromCGRect(a.layer.frame),
a.tag,
a.userInteractionEnabled,
a.alpha,
a.isHidden
];
}
#end
#implementation UIView (Utilities)
+ (void)dumpSuperviews:(UIView *)v msg:(NSString *)msg
{
NSMutableString *str = [NSMutableString stringWithCapacity:256];
while(v) {
[self appendView:v toStr:str];
v = v.superview;
}
[str appendString:#"\n"];
NSLog(#"%#:\n%#", msg, str);
}
+ (void)dumpSubviews:(UIView *)v msg:(NSString *)msg
{
NSMutableString *str = [NSMutableString stringWithCapacity:256];
if(v) [self appendView:v toStr:str];
for(UIView *a in v.subviews) {
[self appendView:a toStr:str];
}
[str appendString:#"\n"];
NSLog(#"%#:\n%#", msg, str);
}
#end

long delay when calling cocoa method

I have a method for saving the contents of a UIScrollView with a user-supplied filename.
Everything works fine, except that there is a long delay when the user taps the "Save" button and the method is called. I can't work out what's calling the delay, nor find a way to indicate to the user that everything is ok, we have not crashed!
I thought the delay was occurring during the renderInContext, but it seems to be happening a lot earlier, when there is not much else going on.
Here is the troublesome method:
- (void)captureViewImage {
NSLog(#"captureViewImage called!");
// long delay happens here!
fileNamer.title = #"Preparing to save...";
// get user's file name
NSString *fileName = fileNamer.fileNameField.text;
// dismiss keyboard
[fileNamer.fileNameField resignFirstResponder];
// dismiss modal view
[self dismissFileNamingFormSheet];
CGRect oldFrame = mainScrollView.frame;
// capture off-screen content
mainScrollView.frame = CGRectMake(0, 0, 1024, 1432);
// make screenshot
UIGraphicsBeginImageContext(mainScrollView.bounds.size);
[mainScrollView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *screenImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// save screenshot in docs dir
NSData *pngData = UIImagePNGRepresentation(screenImg);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
[pngData writeToFile:[documentsDir stringByAppendingPathComponent:fileName]
options:NSDataWritingAtomic error:nil];
// revert scroll view
mainScrollView.frame = oldFrame;
}
fileNamer is a custom class that throws up a UIModalPresentationFormSheet asking the user to supply a name for the file. It looks like this:
#implementation FileNamingViewController
#synthesize fileNameField, newFileName;
- (id)initWithNibName:(NSString *)nibNameOrNil
bundle:(NSBundle *)nibBundleOrNil parent:(TestDriveViewController *) myParent {
if (self == [super initWithNibName:#"FileNamingViewController" bundle:nil]) {
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc]
initWithTitle:#"Save"
style:UIBarButtonItemStyleDone
target:myParent
action:#selector(captureViewImage)];
self.navigationItem.rightBarButtonItem = rightButton;
[rightButton release];
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc]
initWithTitle:#"Cancel"
style:UIBarButtonItemStyleBordered
target:myParent
action:#selector(dismissFileNamingFormSheet)];
self.navigationItem.leftBarButtonItem = leftButton;
[leftButton release];
self.title = #"Save As?";
}
return self;
}
// UITextFieldDelegate
- (void)textFieldDidEndEditing:(UITextField *)textField {
[fileNameField resignFirstResponder];
}
- (void)viewDidLoad {
[fileNameField becomeFirstResponder];
[super viewDidLoad];
}
fileNamer is initialized and released as follows:
- (void)presentFileNamingFormSheet {
fileNamer = [[FileNamingViewController alloc]
initWithNibName:nil
bundle:nil
parent:self];
fileNamingNavCtrl = [[UINavigationController alloc]
initWithRootViewController:fileNamer];
fileNamingNavCtrl.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:fileNamingNavCtrl
animated:YES];
// resize modal form sheet
fileNamingNavCtrl.view.superview.frame = CGRectMake(0, 0, 540, 115);
// reposition modal form sheet
CGPoint position = CGPointMake(self.view.center.x, self.view.center.y - 50);
fileNamingNavCtrl.view.superview.center = position;
}
- (void)dismissFileNamingFormSheet {
[fileNamer release];
[fileNamingNavCtrl release];
[self dismissModalViewControllerAnimated:YES];
}
Output from Time Profiler:
Running (Self) Symbol Name
1109.0ms 37.0% argb32_image_mark_rgb32
328.0ms 10.9% blkclr
171.0ms 5.7% lo_alltraps
134.0ms 4.4% pmap_enter
116.0ms 3.8% png_write_find_filter
102.0ms 3.4% pmap_remove_range
55.0ms 1.8% pmap_get_mapwindow
47.0ms 1.5% vm_page_lookup
47.0ms 1.5% ml_set_interrupts_enabled
43.0ms 1.4% vm_page_grab
38.0ms 1.2% OSAddAtomic64
34.0ms 1.1% hw_lock_to
31.0ms 1.0% alphaProviderGetBytes
30.0ms 1.0% hw_lock_unlock
26.0ms 0.8% png_read_filter_row
25.0ms 0.8% deflateInit_
23.0ms 0.7% vm_map_lookup_entry
23.0ms 0.7% adler32
22.0ms 0.7% memory_object_recover_named
I found out what was causing this. The image I was saving contained a lot of transparent views. For example, I had a lot of UIButtons which had an alpha value of 0.05 to make them more or less disappear. I didn't realise I could just set the button type to custom to make it invisible (I created the view along time ago). Once I set everything in my image view to have an alpha value of 1.0, the saving process became a lot quicker.

Hide button on first of two UIViews, but have it visible on second

So I have a UIViewController (main application controller is a TabBarController). On this there is a UINavigationBar, and a UIBarButtonItem. I'm PRETTY sure I hooked up everything correctly in the Interface Builder and that the outlet in the code is connected to the button in the .xib. It should be because the method works correctly.
Now I have another button on this view that brings up a second view, a UIWebView. I want this UIBarButtonItem, labeled "Back", to make the UIWebView dissapear, and bring back the first UIView, which it DOES DO correctly. However, when you are on the first UIView, there is no need to see the UIBarButtonItem, so how can I hide it but then bring it up for the UIWebView. By the way, both views use the same UINavigationBar, the UIWebView is brought up inside the tab bar and the nav bar.
Here is my code:
#import "WebViewController.h"
#implementation WebViewController
#synthesize webButton;
#synthesize item;
#synthesize infoView;
UIWebView *webView;
+ (UIColor*)myColor1 {
return [UIColor colorWithRed:0.0f/255.0f green:76.0f/255.0f blue:29.0f/255.0f alpha:1.0f];
}
// Creates Nav Bar with default Green at top of screen with given String as title
+ (UINavigationBar*)myNavBar1: (NSString*)input {
UIView *test = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, test.bounds.size.width, 45)];
navBar.tintColor = [WebViewController myColor1];
UINavigationItem *navItem;
navItem = [UINavigationItem alloc];
navItem.title = input;
[navBar pushNavigationItem:navItem animated:false];
return navBar;
}
- (IBAction) pushWebButton {
self.navigationItem.rightBarButtonItem = item;
CGRect webFrame = CGRectMake(0.0, 45.0, 320.0, 365.0);
webView = [[UIWebView alloc] initWithFrame:webFrame];
[webView setBackgroundColor:[UIColor whiteColor]];
NSString *urlAddress = #"http://www.independencenavigator.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
webView.scalesPageToFit = YES;
[webView loadRequest:requestObj];
[self.view addSubview:webView];
[webView release];
}
- (void) pushBackButton {
[webView removeFromSuperview];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
self.navigationItem.rightBarButtonItem = nil;
[super viewDidLoad];
}
#end
Anyone know?
Edit: This answer does not work with nil, but I'm leaving it here as it does work when you want to temporarily replace the back button with another button. See correct answer below in comments.
You might try something like this:
In an App I'm working on there are cases where I'd like to temporarily swap the back button for a cancel button,
so I save a pointer to it:
tempButtonItem = self.navigationItem.leftBarButtonItem;
change the navigationItem.leftBarButtonItem to a cancel button:
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:#selector(cancelButtonPressed)]
autorelease];
And then later when I want to have the back button again I restore it:
self.navigationItem.leftBarButtonItem = self.tempButtonItem;