Open Data/Image To Another View - iphone

I'm trying to find out how to open an item (example: an image) from one view to another.
Basically user taps on a button that I customize into a picture. It will then bring the user to another view with that picture on the view.

Subclass the view controller and make a new init method:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil image:(UIImage*)image
self = [super initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil];
if (self)
{
[imageView setImage:image]
}
return self;
}
imageView is an outlet to a UIImageView in the nib
You can replace the initWithNibName with init if it suits you.
EDIT: Based on your comments you need to pass a reference to the view controller with the image.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil delegate:(id)delegate
self = [super initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil];
if (self)
{
viewDelegate = delegate; // you can use this to reference the view with the image
}
return self;
}

Related

navigation controller not showing titles for tabs

I have created a navigationController. In the OnButtonTap action I am adding a tabBarController to navigationController. Now I want the title of every tab on navigationItemBar. But when I change the title in the viewDidLoad method of viewControllers of tab-bar it won't change.
I tried this in viewDidLoad method of view controller in tab bars.
self.title = #"Friends";
self.navigationItem.title=#"Friends";
[self.navigationItem setHidesBackButton:YES];
and the button is also not hiding...
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title=#"YourTitle";
// Custom initialization
[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:#"selectedImage"]withFinishedUnselectedImage:[UIImage imageNamed:#"unselectedImage"]];
}
return self;
}

InitWithNibName returns viewController but view is nil

Other xib's auto-load fine, but not this one.
When I push this viewcontroller, initWithNibName, loadView, viewDidLoad, and viewWillAppear are called fine, but the view (and all self.xxx objects in #interface) are nil in all these methods, and I am left with an empty window under the navigationbar.
SettingsMain *newVC=[[SettingsMain alloc] initWithNibName:#"SettingsMain" bundle:nil];
[self.navigationController pushViewController:newVC animated:YES];
I was wondering if I can force setting self.view to what's in the .xib, in loadView or initWithNibName, so that all the outlets etc are initalized.
The viewcontroller has the standard code,
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
The problem is that when viewDidLoad is fired, self.view is nil.

XIB is not showing / loading the scrollview but the controls added via code inside the viewdidload being shown

I have addded UIScrollView to my xib but it was not showing on to my view controller.
Also in the view did load method, I have added text boxes to the view controller. This is displayed when I push the view, but not the scrollview which I added inside the xib.
I tried to push the view in two ways
Way 1
SubscribedDetailedViewController *aDetailView = [[[SubscribedDetailedViewController alloc]initWithNibName:#"SubscribedDetailedViewController" bundle:nil]autorelease];
[self.navigationController pushViewController:aPoemDetailView animated:YES];
Way 2
SubscribedDetailedViewController *aDetailView = [[[SubscribedDetailedViewController alloc]init]autorelease];
[self.navigationController pushViewController:aPoemDetailView animated:YES];
Also I placed the below code
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
The above function also gets called.
Why the scrollview which I added into the xib is not being displayed? But the controls added via code inside the viewdidload being shown.

Parameter passing with initWithNibName:

In iphone Application
I need to pass some values to a new viewcontroller object while it create from a method in another viewcontroller class so I can initialize that values in (id)initWithNibName:method of new viewcontroller then I can load those values in viewdidLoad method.
what I want to know is how do I pass the values(parameters) to the constructor(initWithNibName) of a new viewcontrollor Object like constructor overloading in java
give me some code example just showing how initWithNibName called with extra parameters and how to retrieve them in the newly created object
Thanks...
Answer
this is the way I solve the problem "Observation is a object with attributes"
in ViewControllor.h I put
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil set:(Observation *)observation;
in ViewControllor.m file I put
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil set:(Observation *)observation{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization on passed parameter observation object
draftObservation = observation;
}
return self;
}
then I call it this way in another class
ObsevationListView *obsevationListView = [[ObservationViewControllor alloc]
initWithNibName:#"ObservationViewControllor"
bundle:nil set:observer];
[self.navigationController pushViewController:obsevationListView animated:YES];
it works fine. I'm glad if anyone get help from this
You should create another initializer in your class, something like
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil andParam:(id)aParam {
...
self.param = aParam;
}
Another solution is to have a property for that parameter and set it either before or after you call using the following code:
initWithNibName:bundle:

How to SHOW bottombar (tab bar controller)?

I used this to hide the bottom bar
-(BOOL) hidesBottomBarWhenPushed{
return YES;
}
Now i'm at a point where I want to NOT to hide it anymore. What method should I use?
Thanks
Take at look at Elements sample project. They do something like you want, especially in the ElementViewController.m file.
Thats very simple, just use this:
[tabBar setHidesBottomBarWhenPushed:FALSE];
It took me some time putting the puzzle of John together. So here is my final result. In the .m file of my view controller I add this code:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
self.hidesBottomBarWhenPushed = YES;
}
return self;}
Because I use a nib file I had to override the initWithNibName method.
A really simple way:
Class *instanceName = [[Class alloc] init];
instanceName.hidesBottomBarWhenPushed = YES;
...
[navigationController pushViewController:instanceName animated:YES];