perpareForSegue - Passing image name - Blank at First - ios5

I have a thumbnail view controller with two thumbnails. Each have an IBAction setting the image name. The next view should display the full image.
The first time I select a button, the new view opens but is completely blank. I go back to the previous screen (navigation controller) and select the button again and the full image screen shows with the correct full image.
Back out, select the second button and the full image of the first button is displayed.
It appears that the full image is off by one iteration.
Below are some code snippets.
thumbnailViewController.M
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
fullImageViewController *targetVC = (fullImageViewController*)segue.destinationViewController;
targetVC.fullImageName = _imageName;
}
- (IBAction)running1 {
_imageName = #"img_running1.png";
}
- (IBAction)running2 {
_imageName = #"img_running2.png";
}
fullImageViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
_fullImage.image = [UIImage imageNamed: _fullImageName];
}
Any suggestions.

I'm guessing that you have both the IBAction and the Segue hooked up to your buttons? If so this is your issue. The segue occurs before the IBAction. The solution is instead of having the button hooked up to the segue have the IBAction perform it.
- (IBAction)running1 {
_imageName = #"img_running1.png";
[self performSegueWithIdentifier:#"yourSegue" sender:self];
}
This will correct the order by giving you control. otherwise I believe its segue then action.

Related

how to populate an array or any object from one view controller to another when we present the view using story board

I have implemented my iphone app using story board
In my app *i need to present a view from one view to another view not the pus*h,
I have created a screen in story board xib for the second view .
i set up the connection for button in the first view to the second view with 'present' not pust.
Now i need to populate an array to the second view which was presented
i tried following ways but not work out
1:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(UIButton *)sender
{
//Populate detail to BuyView mail page
if ([segue.id
entifier isEqualToString:#"BuyView"])
{
BuyViewController *destViewController = segue.destinationViewController;
destViewController.itemDetailsArray = [_itemDetailsArray objectAtIndex:sender.tag] ;
}
}
2:
- (IBAction)buyItemClick:(UIButton *)sender
{
BuyViewController *destViewController = [[BuyViewController alloc] init];
destViewController.itemDetailsArray = [_itemDetailsArray objectAtIndex:sender.tag] ;
}
On top of what #rdelmar has stated you are passing an object of which may or may not be an array.
Which in turn would mean
destViewController.itemDetailsArray
Would be pointing to an object which may not be an array.
I think what you want to do is
destViewController.itemDetailsArray = _itemDetailsArray;

Loading an image view with saved image in segue

I am using following code to assign an image to an ImageView
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"imgHand"])
{
RingController *ctrl = segue.destinationViewController ;
ctrl.imgHand.image = [[UIImage alloc] initWithContentsOfFile:self.selectedPath];
}
}
However the imgHand shows black and no image is assigned to it.
Image at this path does exist and have already assigned it to an image in CollectionView
Printing description of self->selectedPath:
/var/mobile/Applications/79092B1E-BE77-4583-A39A-C2D4767ADA12/Documents/myHandImage1.png
Your problem is that your "imgHand" image view property isn't insantiated or fully synthesized in the parent view controller's "prepareForSegue" method. It's a NULL object at that point.
Expose a standalone "UIImage" property from your "RingController" and you can set the image via the parent's "prepareForSegue" method call, then in RingController's "viewDidLoad:" you can set the image view to be the image.

segue transition with condition storyboard

I am new to storyboard and xcode (using 4.4)
I would like to implement a login condition, that if accomplished - the segue would work. Otherwise, the user should stay on the same view.
I created 2 UIView: ViewController and Bar Controller.
I also created a segue from ViewController to Bar Controller and set its identifier to loginSegue as modal.
In LoginViewController.m I added the following:
- (IBAction)login:(id)sender {
self.email = self.emailText.text;
self.password = self.passwordText.text;
if ([self.email isEqualToString:#"O"] && [self.password isEqualToString:#"O"])
[self performSegueWithIdentifier:#"LoginSegue" sender:sender];
else
[passwordText setText:#""];
}
When I debug the code - I see that the if skips to else in case of email and password that to not equal to O, however the segue (transition to the new view) still happens.
How can I prevent the user to be transferred to the new view?
BTW, if I remove the if else condition - the user is being transferred to the next view automatically. It seems to me that it was configured somewhere when I drew the segue from one view to the other.
Delete the blank line in between your if and [self perform...]
Additionally, you may want to consider keeping your if-else statements in braces to keep this problem from happening again:
if ([self.email isEqualToString:#"O"] && [self.password isEqualToString:#"O"]){
[self performSegueWithIdentifier:#"LoginSegue" sender:sender];
}else{
[passwordText setText:#""];
}
If this doesn't solve the problem then be sure to varify that the segue is attached to the two controllers and not directly to a button.

Reload the view in iphone (in viewWillAppear)

I got a little app that has a button whose click is handled via
- (IBAction)click:(id)sender { }
Now, what I want is after click() runs, I want the view to refresh/reload itself, so that viewWillAppear() is re-called automatically. Basically how the view originally appears.
Of course I can call viewWillAppear manually, but was wondering if I can get the framework to do it for me?
viewWillAppear is where to put code for when your view will appear, so it is more appropriate to put code that will be called repeatedly into another method like -resetView, which can then be called by both viewWillAppear and your click method. You can then call setNeedsDisplay from within resetView.
-(void)resetView
{
//reset your view components.
[self.view setNeedsDisplay];
}
-(void)viewWillAppear
{
[self resetView];
}
- (IBAction)click:(id)sender
{
[self resetView];
}

Rename standard "edit" button in tableview

I managed (with lots of trial and error) to have my tableview provide only reordering functionality, i.e. my tableview is editable but does not display "delete icons" nor indents the rows upon clicking on the edit button.
Now I would like the button to read "sort" instead of "edit".
I naively tried this:
self.navigationItem.leftBarButtonItem = self.editButtonItem;
self.navigationItem.leftBarButtonItem.title = #"Sort";
which works only once, i.e. it is correctly labeled "Sort", once clicked it renames to "Done", but then--as expected--it re-renames to "Edit".
In order to fix this, I deployed my "own" button on the navbar. This solution works--I can get the button to control the tableview editing mode, reload the data upon change, rename itself, etc--but I cannot get it to "stay highlighted", i.e. the default behaviour of the "Edit" button in a tableview.
Now my question is either:
a) Is there a way to rename (and keep it renamed, e.g. through a callback) the standard "Edit" button?
or
b) Is there a way to have a button behave "modally", i.e. stay selected, like the standard "Edit" button?
Thanks for any idea you might have.
You can put your changes in the - (void) setEditing:(BOOL)editing animated:(BOOL)animated method in your view controller.
- (void) setEditing:(BOOL)editing animated:(BOOL)animated {
//Do super before, it will change the name of the editing button
[super setEditing:editing animated:animated];
if (editing) {
self.navigationItem.leftBarButtonItem.title = #"Done";
self.navigationItem.leftBarButtonItem.style = UIBarButtonItemStyleDone;
}
else {
self.navigationItem.leftBarButtonItem.title = #"Sort";
self.navigationItem.leftBarButtonItem.style = UIBarButtonItemStyleBordered;
}
}