How to use CAPSPageMenu source for Objc? - ios

I am developing IOS project using objective C.
I am going to make sliding tab page.
I found this source from github.
https://github.com/PageMenu/PageMenu
This is the source code which I use CAPSPageMenu.
When
#interface BusinessTabViewController ()
#property(nonatomic) CAPSPageMenu* pageMenu;
#end
#implementation BusinessTabViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableArray *controllerArray = [NSMutableArray array];
UIViewController*controller = [[UIViewController alloc] initWithNibName:#"GongsiyingyeViewController" bundle:nil];
controller.title = #"Sample title";
[controllerArray addObject:controller];
NSDictionary *parameteres = #{CAPSPageMenuOptionMenuItemSeparatorWidth:#(4.3), CAPSPageMenuOptionUseMenuLikeSegmentedControl:#(YES), CAPSPageMenuOptionMenuItemSeparatorPercentageHeight:#(0.1)};
_pageMenu = [[CAPSPageMenu alloc] initWithViewControllers:controllerArray frame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) options:parameteres];
[self.view addSubview:_pageMenu.view];
}
It shows only white screen.
Please help.
Thanks.

The error is not related with PageMenu, Comment the code for Registering Push Notification then try it.
And Before pushing a viewcontroller check that viewcontroller is nil or not.
CAPSPageMenu is working fine in our project.

#interface BusinessTabViewController ()
#property(nonatomic) CAPSPageMenu* pageMenu;
#end
#implementation BusinessTabViewController
-(void) viewDidLayoutSubviews{
NSMutableArray *controllerArray = [NSMutableArray array];
UIViewController*controller = [[UIViewController alloc] initWithNibName:nil bundle:nil];
controller.title = #"Sample title1";
UIViewController*controller1 = [[UIViewController alloc] initWithNibName:nil bundle:nil];
controller1.title = #"Sample title2";
UIViewController*controller2 = [[UIViewController alloc] initWithNibName:nil bundle:nil];
controller2.title = #"Sample title3";
[controllerArray addObject:controller];
[controllerArray addObject:controller1];
[controllerArray addObject:controller2];
NSDictionary *parameteres = #{
CAPSPageMenuOptionMenuItemSeparatorWidth:#(4.3),
CAPSPageMenuOptionUseMenuLikeSegmentedControl:#(YES),
CAPSPageMenuOptionMenuItemSeparatorPercentageHeight:#(0.1),
CAPSPageMenuOptionMenuHeight:#(40),
CAPSPageMenuOptionMenuMargin:#(20),
CAPSPageMenuOptionSelectionIndicatorHeight:#(2.0)
};
_pageMenu = [[CAPSPageMenu alloc] initWithViewControllers:controllerArray frame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) options:parameteres];
[self.view addSubview:_pageMenu.view];
}
I use viewDidLayoutSubviews() for get accurate the size of frame.
It is working fine.

Related

Passing data between tabbarcontroller which have content view and view controllers

I am using xib instead of storyboard.
AppDelegate.m
ViewController1 *ViewController1 = [[ViewController1 alloc] init];
ViewController1.title = NSLocalizedString(#"1", #"1");
ViewController2 *ViewController2 = [[ViewController2 alloc] init];
ViewController2.title = NSLocalizedString(#"2", #"2");
BannerViewController *_bannerViewController1;
_bannerViewController1 = [[BannerViewController alloc] initWithContentViewController:ViewController1];
BannerViewController *_bannerViewController2;
_bannerViewController2 = [[BannerViewController alloc] initWithContentViewController:ViewController2];
_tabBarController = [[UITabBarController alloc] init];
_tabBarController.viewControllers = #[_bannerViewController1,_bannerViewController2];
self.window.rootViewController = _tabBarController;
[self.window makeKeyAndVisible];
ViewController1.m
#import "ViewController1.h"
#import "ViewController2.h"
ViewController2 *cvc = [[ViewController2 alloc] initWithNibName:nil bundle:nil];
cvc.strReceiveValue= "Testing";
ViewController2.h
#property (strong, retain) NSString *strReceiveValue;
ViewController2.m
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"strMortgageAmount: %#", strMortgageAmount);
Any idea why I failed to get the value? I was thinking this could be related to initWithContentViewController.
**
See update below
**
If I understand the question correctly, you are creating a tab bar controller (in AppDelegate?) and wish to pass information to the view controllers associated with the tab bar controller?
If so, take a look at this:
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
[tabBarController setDelegate:self];
UINavigationController *dashTVCnav = [[tabBarController viewControllers] objectAtIndex:0];
Then:
DashTVC *dashTVC = [[dashTVCnav viewControllers] objectAtIndex:0];
dashTVC.managedObjectContext = self.managedObjectContext;
dashTVC.uuid=uuid;
Then in DashTVC.h:
#property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
#property (strong, nonatomic) NSString *uuid;
With this, you pass the managedObjectContect and the uuid to the dashTVC controller.
I hope I understood what you are asking...
+++++++++++++++ UPDATE +++++++++++++++++++++
The original poster was kind enough to give me his sample code. I will post parts of it here with my fix for those who find this through searches in the future
There were several problems, but in short, nothing was being passed to vc2:
1st, nothing was being passed from the appDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
CGRect bounds = [[UIScreen mainScreen] bounds];
self.window = [[UIWindow alloc] initWithFrame:bounds];
self.window.backgroundColor = [UIColor whiteColor];
ViewController1 *vc1 = [[ViewController1 alloc] init];
vc1.title = NSLocalizedString(#"VC1", #"VC1");
ViewController2 *vc2 = [[ViewController2 alloc] init];
vc2.title = NSLocalizedString(#"VC2", #"VC2");
//--- I added this as a test
vc2.strReceiveValue=#"foo";
// and now foo shows up in the debug console when vc2 is fixed
_tabBarController = [[UITabBarController alloc] init];
_tabBarController.viewControllers = #[
[[BannerViewController alloc] initWithContentViewController:vc1],
[[BannerViewController alloc] initWithContentViewController:vc2],
];
self.window.rootViewController = _tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Next, it was necessary to modify viewWillAppear in viewController2.m
- (void)viewWillAppear:(BOOL)animated {
// line below missing
[super viewWillAppear:animated];
NSLog(#"output: %#", strReceiveValue);
}
Hope this helps, and enjoy developing for IOS!

Add UIScrollView with Paging to Existing UIViewController

I'm wanting to add a UIScrollView with paging to go through different views from my existing view controller which is the root view of my app. I also have tab bar and navigation bar controllers along with it. Can I add a scroll view to this view controller to accomplish what I'm wanting, and if so, can someone point me in the right direction on how to go about it?
Here is my view controller.
#import "KFBViewController.h"
#import "ListViewController.h"
#import "ActionAlertsViewController.h"
#import "MarketUpdatesViewController.h"
#import "AgStoriesViewController.h"
#import "KFBNewsViewController.h"
#import "MemberBenefits.h"
#import "SocialNetworks.h"
#import "WebViewController.h"
#import "YouTubeView.h"
#import "KFBFlickrViewController.h"
#import "RSFM.h"
#import "UAPush.h"
#import "TUSafariActivity.h"
#interface KFBViewController ()
{
}
#end
#implementation KFBViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
self.title = NSLocalizedString(#"Home", #"Home");
self.tabBarItem.image = [UIImage imageNamed:#"home"];
self.navigationController.delegate = self;
}
return self;
}
- (void) showMenu
{
NSURL *urlToShare = [NSURL URLWithString:#"https://itunes.apple.com/us/app/kentucky-farm-bureau/id580530986?mt=8"];
NSArray *activityItems = #[urlToShare];
// TUSafariActivity *activity = [[TUSafariActivity alloc] init];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypePrint, UIActivityTypeAssignToContact, UIActivityTypePostToWeibo, UIActivityTypeSaveToCameraRoll];
[self presentViewController:activityVC animated:TRUE completion:nil];
}
- (IBAction)gotoSecondView
{
YouTubeView *youTubeView = [[YouTubeView alloc] initWithNibName:#"YouTubeView" bundle:nil];
youTubeView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:youTubeView animated:YES completion:nil];
}
- (IBAction)gotoPublicAffairs
{
ListViewController *publicAffairs = [[ListViewController alloc]initWithStyle:UITableViewStylePlain];
WebViewController *wvc = [[WebViewController alloc]init];
[publicAffairs setWebViewController:wvc];
publicAffairs.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController pushViewController:publicAffairs animated:YES];
}
- (IBAction)gotoActionAlerts
{
ActionAlertsViewController *actionAlerts = [[ActionAlertsViewController alloc]initWithStyle:UITableViewStylePlain];
WebViewController *wvc = [[WebViewController alloc]init];
[actionAlerts setWebViewController:wvc];
actionAlerts.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController pushViewController:actionAlerts animated:YES];
}
- (IBAction)gotoMarketUpdates
{
MarketUpdatesViewController *marketUpdates = [[MarketUpdatesViewController alloc]initWithStyle:UITableViewStylePlain];
WebViewController *wvc = [[WebViewController alloc]init];
[marketUpdates setWebViewController:wvc];
marketUpdates.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController pushViewController:marketUpdates animated:YES];
}
- (IBAction)gotoAgStories
{
AgStoriesViewController *agStories = [[AgStoriesViewController alloc]initWithStyle:UITableViewStylePlain];
WebViewController *wvc = [[WebViewController alloc]init];
[agStories setWebViewController:wvc];
agStories.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController pushViewController:agStories animated:YES];
}
- (IBAction)gotoKFBNews
{
KFBNewsViewController *kfbNews = [[KFBNewsViewController alloc]initWithStyle:UITableViewStylePlain];
WebViewController *wvc = [[WebViewController alloc]init];
[kfbNews setWebViewController:wvc];
kfbNews.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController pushViewController:kfbNews animated:YES];
}
- (IBAction)gotoMemberBenefits
{
MemberBenefits *memberBenefits = [[MemberBenefits alloc] initWithNibName:nil bundle:nil];
memberBenefits.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController pushViewController:memberBenefits animated:YES];
}
-(IBAction)gotoPhotos:(id)sender
{
KFBFlickrViewController *photosView = [[KFBFlickrViewController alloc] initWithNibName:#"KFBFlickrViewController" bundle:nil];
[self.navigationController pushViewController:photosView animated:YES];
}
- (IBAction)gotoSocialNetworks
{
SocialNetworks *socialNetworks = [[SocialNetworks alloc] initWithNibName:nil bundle:nil];
socialNetworks.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController pushViewController:socialNetworks animated:YES];
}
- (IBAction)gotoFarmMarkets
{
RSFM *rsfm = [[RSFM alloc] initWithNibName:nil bundle:nil];
rsfm.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController pushViewController:rsfm animated:YES];
}
- (IBAction)settingsButtonPressed:(id)sender
{
[UAPush openApnsSettings:self animated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.title = #"Home";
UIBarButtonItem *settingsButton = [[UIBarButtonItem alloc] initWithTitle:#"\u2699" style:UIBarButtonItemStyleBordered target:self action:#selector(settingsButtonPressed:)];
[settingsButton setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:24], UITextAttributeFont,nil] forState:UIControlStateNormal];
self.navigationItem.leftBarButtonItem = settingsButton;
UIBarButtonItem *systemAction = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:#selector(showMenu)];
self.navigationItem.rightBarButtonItem = systemAction;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
#end
This works really well for me:
Declare a property for your UIScrollView, and set your ViewController as a UIScrollViewDelegate
#interface ViewController : UIViewController<UIScrollViewDelegate>
#property (strong, nonatomic) UIScrollView *theScrollView;
#end
**Note that I'm setting up my UIScrollView with code, but it can easily be done with a XIB.
In viewDidLoad: of your ViewController
self.theScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, 300)];
self.theScrollView.delegate = self;
self.theScrollView.pagingEnabled = YES;
self.theScrollView.showsHorizontalScrollIndicator = NO;
self.theScrollView.showsVerticalScrollIndicator = NO;
[self.view addSubview:self.theScrollView];
NSArray *viewArray = [NSArray arrayWithObjects://your UIViews];
for(int i=0; i<viewArray.count; i++)
{
CGRect frame;
frame.origin.x = self.theScrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.theScrollView.frame.size;
UIView *subview = [[UIView alloc] initWithFrame:frame];
[subview addSubview:[viewArray objectAtIndex:i]];
[self.theScrollView addSubview:subview];
}
self.theScrollView.contentSize = CGSizeMake(self.theScrollView.frame.size.width * viewArray.count, self.theScrollView.frame.size.height);
Most paging scrollViews also have a UIPageControl associated with it. To do that, override this UIScrollViewDelegate method:
- (void)scrollViewDidScroll:(UIScrollView *)sender {
CGFloat pageWidth = self.theScrollView.frame.size.width;
int page = floor((self.theScrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
self.thePageControl.currentPage = page;
}
I would perhaps try using UIPageViewController, rather than a regular paging scrollview.
Apple's PhotoScroller sample code provides a very good example of how to use UIPageViewController.
I also have some code on github that modifies PhotoScroller to load the UIPageViewController inside a UIViewController subclass. (In Apple's sample code, the UIPageViewController is the root view controller.)
I have never used a UIPageViewController with different UIViewController subclasses in each page (the PhotoScroller sample code uses PhotoViewControllers in all pages), but I can't see why it couldn't be done with a few modifications to the code.
This link helps for you. Here page controller and scrollview both are used -
PageControl Example in iPhone

UIPopoverController for iPad "must not be called with `nil`" error

I am trying to make an iPhone app work in an iPad but the UIPopoverController is
comming back with error.
- (IBAction)photoTapped1 {
if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone){
// If in editing state, then display an image picker; if not, create and push a photo view controller.
if (self.editing) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:nil];
[imagePicker release];
} else {
RecipePhotoViewController *recipePhotoViewController = [[RecipePhotoViewController alloc] init];
recipePhotoViewController.hidesBottomBarWhenPushed = YES;
recipePhotoViewController.recipe = recipe;
[self.navigationController pushViewController:recipePhotoViewController animated:YES];
[recipePhotoViewController release];
}
}else{
if (self.editing){
self.popover = [[UIPopoverController alloc] initWithContentViewController:popover];
self.popover.delegate =self;
[popover release];
}else{
RecipePhotoViewController *recipePhotoViewController = [[RecipePhotoViewController alloc] init];
recipePhotoViewController.hidesBottomBarWhenPushed = YES;
recipePhotoViewController.recipe = recipe;
[self.navigationController pushViewController:recipePhotoViewController animated:YES];
[recipePhotoViewController release];
}}}
The error I am getting is:
'NSInvalidArgumentException', reason: '-[UIPopoverController initWithContentViewController:] must not be called with nil.'
Anyone available to give me a hand on this code, I have looked on the internet for solutions and samples but can not seem to make it work.
Thank you.
___ added to original question_____
I am adding the recipePhotoViewController here, I am assuming that ImageView manipulation is the same for iPhone and iPad.
my.h File
#class Recipe;
#interface RecipePhotoViewController : UIViewController {
#private
Recipe *recipe;
UIImageView *imageView;
}
#property(nonatomic, retain) Recipe *recipe;
#property(nonatomic, retain) UIImageView *imageView;
#end
Here is my .m file
#implementation RecipePhotoViewController
#synthesize recipe;
#synthesize imageView;
- (void)loadView {
self.title = #"Photo";
imageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.backgroundColor = [UIColor blackColor];
self.view = imageView; }
- (void)viewWillAppear:(BOOL)animated {
imageView.image = [recipe.image valueForKey:#"image"];}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)dealloc {
[imageView release];
[recipe release];
[super dealloc];
} #end
You are initializing the popover controller in a wrong way:
self.popover = [[UIPopoverController alloc] initWithContentViewController:popover];
You should pass the controller you would like to display inside of the popover -- not the popover itself (which is nil since you have not yet initialised it)!
Maybe this would do it for you?
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
self.popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
If this is correct, then you should also present the pop over you have just created: – presentPopoverFromRect:inView:permittedArrowDirections:animated:
-- e.g.:
[self.popover presentPopoverFromRect:sender.frame inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
where sender is the argument to :
- (IBAction)photoTapped1:(id)sender {
The content of your popover which you store in the variable popover is obviously nil. I can't see it ever being created in the code you provided.
Maybe you intended to present the Recipe photo controller as the content of the popover. In that case you would do something like
RecipePhotoViewController *recipePhotoViewController = [[RecipePhotoViewController alloc] init];
self.popover = [[UIPopoverController alloc] initWithContentViewController:recipePhotoViewController];
problem is in this line of your code ,
self.popover = [[UIPopoverController alloc] initWithContentViewController:popover];
try like this
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 400, 320, 260)];
popoverContent.view = popoverView;
//Add what ever you want popoverView
self.popover = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
self.popover.delegate =self;

Loading data in one tab, viewing it another but the table won't reload

I have a tab controller with 4 tabs in it. In the 2nd tab I am entering data and saving that data to a plist. In the 4th tab I am reading the plist back, making an array of one of the dictionary items (company names) and displaying them in a table. I am doing this in the viewDidLoad method.
This works fine for existing data. However, when I add data in the 2nd tab and then go to the 4th tab I can't figure out how to get the table to reload the data...I've tried [table reloadData] in the viewDidAppear method, no luck. Also tried to have a button to reload the data but nothing.
Could someone point me in the right direction on this?
Here's some code:
AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//We need to implement the view controllers within the tab controller and make the tab controller the root controller of our app - note we are only using view 1-4 at first.
FirstViewController *fistView = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
ThirdViewController *thirdView = [[ThirdViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil];
FourthViewController *fourthView = [[FourthViewController alloc] initWithNibName:#"FourthViewController" bundle:nil];
NSArray *viewControllersArray = [[NSArray alloc] initWithObjects:fistView, secondView, thirdView, fourthView, nil];
self.tabController = [[UITabBarController alloc] init];
[self.tabController setViewControllers:viewControllersArray animated:YES];
self.window.rootViewController = self.tabController;
//end custom code
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
in my FourthViewController.h:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//add our own image to the tab bar
self.title = #"Results";
self.tabBarItem.image = [UIImage imageNamed:#"btnResults.png"];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
newFileManager = [FileManager new];
NSMutableDictionary* surveyResults = [newFileManager readPlist];
NSMutableArray* tempArray = [[NSMutableArray alloc] init];
for(NSString* thisCompanyName in surveyResults) {
[tempArray addObject:thisCompanyName];
}
companyNames = [[NSArray alloc] initWithArray:tempArray];
NSArray* sortedCompanyNames = [companyNames sortedArrayUsingSelector:#selector(localizedCaseInsensitiveCompare:)];
self.companyNamesTable = sortedCompanyNames;
}
Need to post more code to be sure but I would say you are not initializing the 4th tab everytime. Meaning you code is something like this.
init{
[tab4 init]
}
callview{
[pushView tab4]
}
where as if you did
init{
}
callview{
[tab4 init]
[pushView tab4]
}
(meaning dont init the 4tab till your going to use it)
it should query the plist fresh, without any prior query results in the way

xCode 4.2 UITableView drilldown

I'm a newbie to the xCode world and I had a few questions regarding my application setup.
My application a list of Authors, click on author and get author detail plus book titles, and then click on the book title and get book information, but I'm unable to figure out the show detail part.
I have established a tab view controller that displays UIViewControllers in the window.
//create view controllers
UIViewController *vc1 = [[HomeViewController alloc] init];
UIViewController *vc2 = [[AuthorViewController alloc] init];
UIViewController *vc3 = [[BooksViewController alloc] init];
UIViewController *vc4 = [[GenreViewController alloc] init];
UIViewController *vc5 = [[UserViewController alloc] init];
//create instance of tab bar
self.tabBar = [[UITabBarController alloc] init];
//add views to tab bar
self.tabBar.viewControllers = [NSArray arrayWithObjects:vc1,vc2,vc3, vc4, vc5, nil];
self.window.rootViewController = self.tabBar;
//self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
//self.window.backgroundColor = [UIColor whiteColor];
[_window addSubview:_tabBar.view];
[self.window makeKeyAndVisible];
return YES;
This works perfectly. My first view "AuthorViewContoller" is a table and I can display data, however I can NOT get the detailController to show.
My AuthorViewController viewDidLoad method
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.author= [[NSArray alloc] initWithObjects:#"One", #"two", nil];
self.detailController = [[AuthorDetailController alloc] init];
and my methoddidSelectRowAtIndexPath:
if(indexPath.row == 0)
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
AuthorDetailController *dc = [[AuthorDetailController alloc] initWithNibName:#"AuthorDetailController" bundle:nil];
dc.title = [author objectAtIndex:indexPath.row];
[self.navigationController pushViewController:dc animated:YES];
}else{
[self.navigationController pushViewController:detailController animated:YES];
}
I'm declaring detailController in my AuthorViewController.h file.
#property (nonatomic, retain) IBOutlet AuthorDetailController *detailController;
You have to actually create a UINavigationController, and have it be part of your controller hierarchy, before you can use pushViewController:animated:. You should really try setting this up in a NIB, instead of code, but in your code you can try this in place of your current vc2 initialization:
UIViewController *vc2 = [[UINavigationController alloc] initWithRootViewController:[[AuthorViewController alloc] init]];

Resources