After had many research, I don't find solution.So that I decided post my question. I have an ** IBOutlet UITextField *txtUsername at DetailViewController.h. At FormViewController I have a UIScrollview, and then I add [self.scrollView addSubview:DetailView.view]. The problem is when stand at DetailViewController.m I call txtUsername.text it return a nil value. Any suggestion?
It seems that you are trying to embed one view controller within another. I recommend using a Container view and then loading DetailViewController into that. Simply adding the view, as you are in your code, is not going to be enough. You probably want all the behavior in DetailViewController to work.
After debug many time I found the problem is:
At FormViewController I have method:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = #"Add new user";
DetailView = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
}
return self;
}
And method (Which had call at viewDidLoad)
-(void) loadViewBySegment {
[DetailView.view removeFromSuperview];
[self.scrollView addSubview:DetailView.view];
}
and ViewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:#"Save" style:UIBarButtonItemStylePlain target:self action:#selector(save)];
self.navigationItem.rightBarButtonItem = saveButton;
if(user)
{
userDetailView.user = user;
}
[self loadViewBySegment];
// Do any additional setup after loading the view from its nib.
}
and
-(void)save{
[[userDetailView userDetailInstance] insertData];
}
And then at DetailViewController I create insertData function
-(void)insertData{
User *object = [[User alloc] init];
object.Username = txtUsername.text;
object.FullName = txtFullname.text;
object.Title = txtTitle.text;
object.Role = [NSNumber numberWithInt:[txtRole.text intValue]];
object.UserInitial =txtInital.text;
object.Status = YES;
object.AddedTime = [NSDate date];
object.UpdatedTime = [NSDate date];
object.Phone = #"0949931124";
object.Password = #"123456";
[[DBManager sharedInstant] insertData:BUsers item:[object dictionary] target:self];
}
The reason why texfield.text is nil:
At FormViewController I call an instance of DetailViewController it's mean DetailViewController - will be have new alloc init. so that textfield's value will which had enter by user before will be reset.
The right way I need to do is: change the save function at FormViewController:
-(void)save{
[DetailView insertData];
}
P/S:Lesson Learn for me is: be careful when use Instace (Singleton Design partner).
Related
I have a double-tap gesture on a view controller iRpImageViewerViewController (topmost on the navigation stack), and each time a view on iRpImageViewerViewController is double-tapped, it pushes a image editor view controller iRpImageEditorViewController onto the stack, that's why there are several of them, none of which appeared. Each time I double-tap, it's added, but never appears. self is simply the class that houses this double-tap gesture iRpImageViewerViewController, and does in fact have a navigationController per the LLDB output
po self.navigationController returns a navigation controller as expected.
po self.navigationController viewControllers shows a new view controller being added to the list with each pushViewController statement encountered, yet the pushed item won't show up on screen.
I shouldn't have to push and then move to front, right?? Doesn't the push automatically make it the frontmost view controller?
Note that my navigation controller is NOT the root controller in my hierarchy, starting from the window. I have a full screen map view controller, then a half-screen 'dashboard' view controller, then within that I have a window on the dashboard that has a picture, and that picture is itself a view controller. So starting with the picture view controller, shown here, you can walk through everything that happens
#implementation iRpDashboardHeaderImagesViewController
{
IGGridView *theGridViewControl;
UIView *theGridParentView;
iRpImageSet *thePropertyImageSet;
iRpDashboardViewController *dashboardViewController;
UIImageView *primaryImageMarker;
UINavigationController *imageEditorNavController;
iRpImageViewerViewController *imageViewerVC;
}
-(id)initWithParentViewController:(iRpDashboardViewController*)parentController
{
self = [super init];
if (self)
{
dashboardViewController = parentController;
}
return self;
}
-(void)loadView
{
// Just a basic size to get started... the final size is set later in another method. I believe actual height will be 220
CGRect theGridRectangle = CGRectMake(0, 0, 375, 220);
theGridViewControl = [[IGGridView alloc]initWithFrame:theGridRectangle style:IGGridViewStyleSingleCellPaging];
// Set additional properties to configure the grid view
theGridViewControl.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
theGridViewControl.selectionType = IGGridViewSelectionTypeCell;
theGridViewControl.contentMode = UIViewContentModeScaleAspectFit;
theGridViewControl.allowHorizontalBounce = NO;
theGridViewControl.alwaysBounceVertical = NO;
self.view = theGridViewControl;
}
-(void)viewDidLoad
{
[super viewDidLoad];
imageEditorNavController = [[UINavigationController alloc] init];
}
-(void)presentImageViewerForCellAtPath:(IGCellPath*)path
{
iRpImageAndMedia *imageAndMediaItem = [thePropertyImageSet objectAtIndex:path.columnIndex];
imageViewerVC = [[iRpImageViewerViewController alloc] initWithParentViewController:self imageSet:thePropertyImageSet initialImageAndMedia:imageAndMediaItem];
imageViewerVC.edgesForExtendedLayout = UIRectEdgeNone;
imageViewerVC.navigationItem.title = dashboardViewController.parcelNbr;
imageViewerVC.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(imageEditorDone)];
// Create a navigation controller to embed the image viewer view controller inside.
[imageEditorNavController pushViewController:imageViewerVC animated:YES];
[self presentViewController:imageEditorNavController animated:YES completion:^(void)
{
}];
}
-(void)imageEditorDone
{
[self dismissViewControllerAnimated:YES completion:^{}];
}
}
...
#implementation iRpImageViewerViewController
{
IGGridView *theMainImageGridviewControl;
iRpImageSet *thePropertyImageSet;
iRpImageFilmstripViewController *theFilmstripViewController;
iRpImageAndMedia *initialMediaItem;
UIImageView *primaryImageMarker;
iRpImageEditorViewController *imageEditorVC;
UIViewController *theParentViewController;
}
-(id)initWithParentViewController:(UIViewController*)parentViewController imageSet:(iRpImageSet*)imageSet initialImageAndMedia:(iRpImageAndMedia*)imageAndMedia
{
self = [super initWithNibName:#"iRpImageViewerViewController" bundle:nil];
if (self)
{
theParentViewController = parentViewController;
theFilmstripViewController = [[iRpImageFilmstripViewController alloc] initWithParentViewController:self imageSet:imageSet initialImageAndMedia:imageAndMedia];
initialMediaItem = imageAndMedia;
thePropertyImageSet = imageSet;
}
return self;
}
-(void)viewDidLoad
{
[super viewDidLoad];
theMainImageGridviewControl = [[IGGridView alloc]initWithFrame:self.mainImagePlaceholderView.frame style:IGGridViewStyleSingleCellPaging];
// Set additional properties to configure the grid view
theMainImageGridviewControl.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
theMainImageGridviewControl.selectionType = IGGridViewSelectionTypeCell;
theMainImageGridviewControl.contentInset = UIEdgeInsetsZero;
theMainImageGridviewControl.allowHorizontalBounce = NO;
theMainImageGridviewControl.alwaysBounceHorizontal = NO;
theMainImageGridviewControl.alwaysBounceVertical = NO;
[self.mainImagePlaceholderView addSubview:theMainImageGridviewControl];
[self addAChildViewController:theFilmstripViewController toViewWithTag:self.filmstripPlaceholderView.tag];
}
-(void)addGestureRecognizersToCell:(IGGridViewImageCell*)cell
{
static NSMutableArray *recognizers;
UITapGestureRecognizer *doubleTapRecognizer;
UILongPressGestureRecognizer *longPressRecognizer;
if (!recognizers)
{
recognizers = [[NSMutableArray alloc] init];
doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleDoubleTapRecognizer:)];
doubleTapRecognizer.numberOfTapsRequired = 2;
longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(handleLongPressRecognizer:)];
[recognizers addObject:doubleTapRecognizer];
[recognizers addObject:longPressRecognizer];
}
// Don't do anything because already processed.
[cell removeGestureRecognizer:doubleTapRecognizer];
[cell removeGestureRecognizer:longPressRecognizer];
[cell registerGestures:recognizers];
}
-(void)handleDoubleTapRecognizer:(UITapGestureRecognizer*)recognizer
{
NSLog(#"Double Tapped on ImageViewerViewController's main image, so opening editor");
IGCellPath *pathForCurrentCell = [self pathForCurrentCell];
iRpImageAndMedia *imageAndMediaItem = [thePropertyImageSet objectAtIndex:pathForCurrentCell.columnIndex];
imageEditorVC = [[iRpImageEditorViewController alloc] initWithImageAndMediaItem:imageAndMediaItem];
imageEditorVC.navigationItem.title = #"Photo Details Editor";
imageEditorVC.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(imageEditorDone)];
imageEditorVC.edgesForExtendedLayout = UIRectEdgeNone;
[self.navigationController pushViewController:imageEditorVC animated:YES];
}
-(void)imageEditorDone
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
-(void)imageEditorCancelled
{
[self dismissViewControllerAnimated:YES completion:nil];
}
}
...
This class below is the one that keeps being added to the navigation controller, but never appears.
...
#implementation iRpImageEditorViewController
{
__weak IBOutlet UISwitch *primarySwitch;
__weak IBOutlet UISwitch *postToWebSwitch;
__weak IBOutlet UITextView *descriptionView;
__weak IBOutlet UIImageView *imageView;
__weak IBOutlet UITextField *mediaDate;
__weak IBOutlet UITextField *orderNbr;
__weak IBOutlet UITextField *updatedBy;
__weak IBOutlet UITextField *updateDate;
iRpImageAndMedia *theImageAndMediaItem;
}
-(id)initWithImageAndMediaItem:(iRpImageAndMedia*)imageAndMediaItem
{
if (self = [super initWithNibName:#"iRpImageEditorViewController" bundle:nil])
{
theImageAndMediaItem = imageAndMediaItem;
}
return self;
}
-(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self populateUserInterface];
}
-(void)populateUserInterface
{
imageView.image = [theImageAndMediaItem pictureForViewOfSize:imageView.bounds.size];
primarySwitch.on = [theImageAndMediaItem isPrimary];
postToWebSwitch.on = [[theImageAndMediaItem.mediaManagedObj valueForKey:#"postToWeb"] boolValue];
descriptionView.text = [theImageAndMediaItem.mediaManagedObj valueForKey:#"desc"];
updatedBy.text = [theImageAndMediaItem.mediaManagedObj valueForKey:#"updatedBy"];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:#"MM/dd/yyyy"];
[dateFormat setTimeZone:[NSTimeZone localTimeZone]];
NSString *theFormattedDate = [dateFormat stringFromDate:[theImageAndMediaItem.mediaManagedObj valueForKey:#"updateDate"]];
updateDate.text = theFormattedDate;
orderNbr.text = [[theImageAndMediaItem.mediaManagedObj valueForKey:#"order"] stringValue];
}
-(IBAction)postToWebValueChanged:(id)sender
{
UISwitch *theSwitch = sender;
[theImageAndMediaItem.mediaManagedObj setValue:[NSNumber numberWithBool:theSwitch.on] forKey:#"postToWeb"];
}
-(IBAction)primaryValueChanged:(id)sender
{
UISwitch *theSwitch = sender;
[theImageAndMediaItem.mediaManagedObj setValue:[NSNumber numberWithBool:theSwitch.on] forKey:#"primary"];
}
...
-(void)handleDoubleTapRecognizer:(UITapGestureRecognizer*)recognizer
{
NSLog(#"Double Tapped on ImageViewerViewController's main image, so opening editor");
IGCellPath *pathForCurrentCell = [self pathForCurrentCell];
iRpImageAndMedia *imageAndMediaItem = [thePropertyImageSet objectAtIndex:pathForCurrentCell.columnIndex];
imageEditorVC = [[iRpImageEditorViewController alloc] initWithImageAndMediaItem:imageAndMediaItem];
imageEditorVC.navigationItem.title = #"Photo Details Editor";
imageEditorVC.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(imageEditorDone)];
imageEditorVC.edgesForExtendedLayout = UIRectEdgeNone;
[self.navigationController pushViewController:imageEditorVC animated:YES];
}
I need a little help about my code. I want to create a custom bar graph. I did all the coding. When I create the objects in my custom class view it works like a charm. However, I want to make it generic. I would like to create it in ViewController. I also add a view in storyboard and change the class name to my custom class name.
It doesn't work when I try like this.
#implementation ViewController
-(void)viewDidLoad {
[super viewDidLoad];
GCBarGraphRow *first = [[GCBarGraphRow alloc]init];
first.backgroundColor = [UIColor redColor];
first.value = 20;
GCBarGraphRow *second = [[GCBarGraphRow alloc]init];
second.backgroundColor = [UIColor brownColor];
second.value = 40;
GCBarGraphColumn *container = [[GCBarGraphColumn alloc]init];
container.values = #[first,second];
NSLog(#"View Controller %#",container.values);
self.myGraph.array = container;
}
But when I try to create it in my custom view class it works.
#implementation GCBarGraphView
-(id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
barNumber = [array.values count];
//NSLog(#"%#",array.values);
showDifference = NO;
showShadow = NO;
gradientColor = NO;
drawBaseLine = YES;
[self baseClassInit];
}
return self;
}
-(void)baseClassInit {
GCBarGraphRow *first = [[GCBarGraphRow alloc]init];
first.backgroundColor = [UIColor redColor];
first.value = 20;
GCBarGraphRow *second = [[GCBarGraphRow alloc]init];
second.backgroundColor = [UIColor brownColor];
second.value = 40;
GCBarGraphColumn *container = [[GCBarGraphColumn alloc]init];
container.values = #[first,second];
}
If you're creating a view in the storyboard and assign it's class to your CGBarGraphRow, you also need to create an outlet to your view controller.
Then you don't have to initialize it manually from the view controller code. Your constructor initWithCoder will be called automatically.
Update:
Try this. In the storyboard create the following:
- UIView with proper frame and assign custom class to CGBarGraphView
- Insert into that view two more and assign their classes to GCBarGraphRow
In your CGBarGraphView class create two outlets and bind them to the proper views in the storyboard:
#property (nonatomic, weak) IBOutlet GCBarGraphRow *row1;
#property (nonatomic, weak) IBOutlet GCBarGraphRow *row2;
Remove the code you have above for the view controller - it's not needed. Leave something like that in the CGBarGraphView code:
-(id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
}
return self;
}
-(void)viewDidLoad {
GCBarGraphColumn *container = [[GCBarGraphColumn alloc]init];
container.values = #[self.row1,self.row2];
... whatever else you need to initialize
}
in my ios app, i have a view with several cells called PersonalDetailTVC. After selecting a value on another view the app returns to PersonalDetailTVC, and I want that the background color of certain cell changes depending on the new value, but the colour only changes when I return to the view again. Can you help me, please?
#import "PersonDetailTVC.h"
#implementation PersonDetailTVC
#synthesize delegate;
#synthesize person = _person;
#synthesize selectedRole;
#synthesize personFirstnameTextField = _personFirstnameTextField;
#synthesize personSurnameTextField = _personSurnameTextField;
#synthesize personRoleTableViewCell = _personRoleTableViewCell;
#synthesize groupColorTableViewCell = _groupColorTableViewCell;
- (void)viewDidLoad
{
NSLog(#"Setting the value of fields in this static table to that of the passed Person");
//self.personNameTextField.text = self.person.name;
self.personFirstnameTextField.text = self.person.firstname;
self.personSurnameTextField.text = self.person.surname;
self.personRoleTableViewCell.textLabel.text = self.person.inRole.name;
self.groupColorTableViewCell.textLabel.text = self.person.hasColor.color;
self.selectedRole = self.person.inRole; // ensure null role doesn't get saved.
if ([self.person.hasColor.color isEqual:#"Grey"]){
self.groupColorTableViewCell.backgroundColor = [UIColor colorWithRed:21.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:1];
}
UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(dismissKeyboard)];
[tgr setCancelsTouchesInView:NO];
[self.tableView addGestureRecognizer:tgr];
[super viewDidLoad];
}
- (void)viewDidUnload
{
//[self setPersonNameTextField:nil];
[self setPersonFirstnameTextField:nil];
[self setPersonSurnameTextField:nil];
[self setPersonRoleTableViewCell:nil];
[self setGroupColorTableViewCell:nil];
[super viewDidUnload];
}
- (IBAction)save:(id)sender
{
NSLog(#"Telling the PersonDetailTVC Delegate that Save was tapped on the PersonDetailTVC");
self.person.firstname = self.personFirstnameTextField.text; // Set Firstname
self.person.surname = self.personSurnameTextField.text; // Set Surname
[self.person setInRole:self.selectedRole];
[self.person setHasColor:self.selectedRole];// Set Relationship!!!
[self.person.managedObjectContext save:nil]; // write to database
[self.delegate theSaveButtonOnThePersonDetailTVCWasTapped:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender // !
{
if ([segue.identifier isEqualToString:#"Person Role Segue"])
{
NSLog(#"Setting PersonDetailTVC as a delegate of PersonRoleTVC");
PersonRoleTVC *personRoleTVC = segue.destinationViewController;
personRoleTVC.delegate = self;
personRoleTVC.selectedPerson = self.person;
}
else {
NSLog(#"Unidentified Segue Attempted!");
}
}
- (void)dismissKeyboard {
[self.view endEditing:TRUE];
}
- (void)roleWasSelectedOnPersonRoleTVC:(PersonRoleTVC *)controller
{
self.personRoleTableViewCell.textLabel.text = controller.selectedRole.name;
self.groupColorTableViewCell.textLabel.text = controller.selectedRole.color;
self.selectedRole = controller.selectedRole;
NSLog(#"PersonDetailTVC reports that the %# role was selected on the PersonRoleTVC", controller.selectedRole.name);
[controller.navigationController popViewControllerAnimated:YES];
}
#end
As far as i can see, you're not changing a color anywhere in the provided code. While reading the code, i noticed a few things, so i thought i share it with you, maybe it helps:
If I understand correctly you are using a UITableViewCell without a UITableView. This is actually not a problem as UITableViewCell derives from UIView, but the cell will not have the behaviour of a UITableViewCell (because this is usually controlled by a UITableView). When adding a UITableViewCell manually as a subview, the cell will have the default behaviour of a UIView.
In your save: method I see the following 2 lines:
[self.person setInRole:self.selectedRole];
[self.person setHasColor:self.selectedRole];// Set Relationship!!!
Are you intentionally passing self.selectedRole to a property hasColor (or setHasColor: method)? Since I don't know the types of these objects this might be OK, but looks like you should set a color there.
In the roleWasSelectedOnPersonRoleTVC: method your are currently setting the text property twice:
self.personRoleTableViewCell.textLabel.text = controller.selectedRole.name;
self.groupColorTableViewCell.textLabel.text = controller.selectedRole.color;
Shouldn't that last line be something like this?
self.groupColorTableViewCell.textLabel.textColor = controller.selectedRole.color;
I watched the WWDC video on UIViewController Containment and read through this blog post: http://www.cocoanetics.com/2012/04/containing-viewcontrollers/
but I can't get my initial view controller to show. Is there something I am missing? In my ContainerViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
_homeViewController = [[HomeViewController alloc] init];
_detailViewController = [[DetailViewController alloc] init];
[self setSubViewControllers:#[_homeViewController, _detailViewController]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (_selectedViewController.parentViewController == self) {
// nothing to do
return;
}
// adjust the frame to fit the container view
_selectedViewController.view.frame = _containerView.bounds;
// make sure that it resizes on rotation automatically
_selectedViewController.view.autoresizingMask = _containerView.autoresizingMask;
// add as child VC
[self addChildViewController:_selectedViewController];
// add it to container view, calls willMoveToParentViewController for us
[_containerView addSubview:_selectedViewController.view];
// notify that move is done
[_selectedViewController didMoveToParentViewController:self];
}
- (void)loadView {
// set up the base view
CGRect frame = [[UIScreen mainScreen] bounds];
UIView *aView = [[UIView alloc] initWithFrame:frame];
aView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
aView.backgroundColor = [UIColor blueColor];
// set up content view
_containerView = [[UIView alloc] initWithFrame:frame];
_containerView.backgroundColor = [UIColor grayColor];
_containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[aView addSubview:_containerView];
self.view = aView;
}
- (void)setSubViewControllers:(NSArray *)subViewControllers {
_subViewControllers = [subViewControllers copy];
if (_selectedViewController) {
// remove previous VC
}
_selectedViewController = _subViewControllers[0];
}
My ContainerViewController is the initial view controller in my storyboard. I see that it shows on the simulator, but the HomeViewController (the first child view controller in my container) does not show.
When I step through the debugger, the subViewControllers property of my ContainerViewController does have the homeViewController and detailViewController in it. The viewDidLoad of HomeViewController also does get called. I just don't see anything on screen except the background color of the ContainerViewController.
Any thoughts? Thanks.
So I'm not the brightest person in the world, but the reason nothing was being shown on the screen was because the nibs were in the storyboard and I needed to do this instead:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPad" bundle:nil];
_homeViewController = [storyboard instantiateViewControllerWithIdentifier:#"HomeViewController"];
_detailViewController = [storyboard instantiateViewControllerWithIdentifier:#"DetailViewController"];
Hopefully this helps someone who is also not familiar with Storyboards yet.
You have an NSArray, but you are trying to access it as a C array.
_subViewControllers[0]
should be:
[_subViewControllers objectAtIndex:0];
That being said, you seem to have some code that could be better in other methods. I would personally clean this up a lot and make it much simpler. I would remove loadView and _containerView, and just use self.view as one normally would. For what you are trying to do, there really doesn't even seem a need to track parent and child view controllers. Anyway, this is how I would do it:
#interface ContainerViewController ()
#property (nonatomic, retain) NSArray *subViewControllers;
#end
#implementation ObservationReportViewController {
UIViewController *_selectedViewController;
}
#synthesize subViewControllers = _subViewControllers;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
HomeViewController *homeViewController = [[HomeViewController alloc] init];
homeViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
// Retain the view controllers.
self.subViewControllers = #[homeViewController, detailViewController];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self setSelectedViewController: [_subViewControllers objectAtIndex:0]];
}
-(void)setSelectedViewController:(UIViewController *)selectedViewController {
if (_selectedViewController != selectedViewController) {
[_selectedViewController.view removeFromSuperview];
_selectedViewController = selectedViewController;
// adjust the frame to fit the container view
[self.view addSubview:_selectedViewController.view];
//_selectedViewController.view.frame = _containerView.bounds;
_selectedViewController.view.frame = self.view.bounds;
}
}
If you set the InitialViewController through the storyboard in a different storyb than the MainStoryboard, then you need to update the project settings to use that new storyboard.
Go to project settings, General and set the Main Interface setting to the new storyboard
I have been trying to implement NIPhotoAlbumScrollView http://jverkoey.github.com/nimbus/interface_n_i_photo_album_scroll_view.html. I am using photos in app bundle. But this code is not working. Here is link of full code http://pastebin.com/ysvPL6ee
AlbumViewController.h
#interface AlbumViewController : NIToolbarPhotoViewController <NIPhotoAlbumScrollViewDataSource>
{
NSMutableArray* photoInformation;
}
#end
#import "AlbumViewController.h"
#implementation AlbumViewController
#pragma mark - View lifecycle
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
photoInformation = [[NSMutableArray alloc] init];
for(int i=0; i<2; i++)
{
NSString* originalImageSource = #"Photo001.jpg";
NSString* thumbnailImageSource = #"img1.jpg";
NSDictionary* prunedPhotoInfo = [NSDictionary dictionaryWithObjectsAndKeys:
originalImageSource, #"originalSource",
thumbnailImageSource, #"thumbnailSource",
nil];
[photoInformation addObject:prunedPhotoInfo];
}
self.photoAlbumView.dataSource = self;
self.title = NSLocalizedString(#"Loading...", #"Navigation bar title - Loading a photo album");
[self.navigationController setNavigationBarHidden:NO];
[self.photoAlbumView reloadData];
}
Edit
Not working means - It does not load images and not even show loading image
self.photoAlbumView.loadingImage = [UIImage imageWithContentsOfFile:
NIPathForBundleResource(nil, #"img1.jpg")];
The - (NSInteger)numberOfPagesInPagingScrollView:(NIPagingScrollView *)pagingScrollView or any other methods are not being called.
I forgot to add [super loadView] at the beginning of the loadView method.
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
[super loadView];
photoInformation = [[NSMutableArray alloc] init];
for(int i=0; i<2; i++)
{
NSString* originalImageSource = #"Photo001.jpg";
NSString* thumbnailImageSource = #"img1.jpg";
NSDictionary* prunedPhotoInfo = [NSDictionary dictionaryWithObjectsAndKeys:
originalImageSource, #"originalSource",
thumbnailImageSource, #"thumbnailSource",
nil];
[photoInformation addObject:prunedPhotoInfo];
}
self.photoAlbumView.dataSource = self;
self.title = NSLocalizedString(#"Loading...", #"Navigation bar title - Loading a photo album");
[self.navigationController setNavigationBarHidden:NO];
[self.photoAlbumView reloadData];
}