I am trying to build a small app. It's a tabbed app with 3 tabs: photos, videos, documents
Each tab displays a tableview to select wich gallery, video, document is to be shown; Videos work fine.
I'm having trouble with photo galleries. I use Fgallery which is working fine from the sample: Fgallery git
.h
#import <UIKit/UIKit.h>
#import "FGalleryViewController.h"
#interface FirstViewController : UIViewController <FGalleryViewControllerDelegate, UITableViewDelegate, UITableViewDataSource> {
NSArray *localCaptions;
NSArray *localImages;
NSArray *networkCaptions;
NSArray *networkImages;
FGalleryViewController *localGallery;
FGalleryViewController *networkGallery;
}
#property (nonatomic, strong) UITableView *myTableView;
#end
.m
#import "FirstViewController.h"
#implementation FirstViewController
#synthesize myTableView;
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect tableViewRect = self.view.bounds;
UITableView *tableView = [[UITableView alloc]
initWithFrame:tableViewRect
style:UITableViewStylePlain];
self.myTableView = tableView;
self.myTableView.autoresizingMask =
UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleWidth;
[self.view addSubview:self.myTableView];
self.myTableView.dataSource = self;
self.myTableView.delegate = self;
}
and
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog( #"Choix Table");
if( indexPath.row == 0 ) {
NSLog( #"selection 1");
localGallery = [[FGalleryViewController alloc] initWithPhotoSource:self];
[self.navigationController pushViewController:localGallery animated:YES];
}
else if( indexPath.row == 1 ) {
networkGallery = [[FGalleryViewController alloc] initWithPhotoSource:self];
[self.navigationController pushViewController:networkGallery animated:YES];
...
}
I really don't know how to display the gallery. The didSelectRowAtIndexPath is the one from fgallery, I tried to modify it to show the viewm but I'm new to Objective-C and I'm stuck.
Any help or guideline will be appreciated.
Thanks
I added
if( indexPath.row == 0 ) {
NSLog( #"selection 1");
localGallery = [[FGalleryViewController alloc] initWithPhotoSource:self];
// Create the navigation controller and present it modally.
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:localGallery];
[self presentModalViewController:navigationController animated:YES];
View shows ok now but I am missing the back button
In FGalleryViewController.m, I added btn2 to the navigation controller
- (void)setUseThumbnailView:(BOOL)useThumbnailView
{
_useThumbnailView = useThumbnailView;
if( self.navigationController ) {
if (_useThumbnailView) {
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:#"See All" style:UIBarButtonItemStylePlain target:self action:#selector(handleSeeAllTouch:)] ;
[self.navigationItem setRightBarButtonItem:btn animated:YES];
UIBarButtonItem *btn2 = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:self action:#selector(dismissModalViewControllerAnimated:)] ;
[self.navigationItem setLeftBarButtonItem:btn2 animated:YES];
}
else {
[self.navigationItem setRightBarButtonItem:nil animated:NO];
}
}
}
And voilĂ
Related
Hello I'm using this library to show my PopOver which contain tableView with searchBar.
The problem is that one user try to select row from the tableView instead dismissing the popOver and displaying the slected row in hole screen I got this :
.
I've tried to use [self.parentViewController.navigationController ...] to push my view but didn't worked.
This is my popOver code (in MainVC.h):
-(IBAction)showPopoverSearch:(id)sender{
UIBarButtonItem *btn = (UIBarButtonItem *) sender;
NSInteger width = 600;
NSInteger height = 400;
SearchViewController *searchVC = [self.storyboard instantiateViewControllerWithIdentifier:#"searchView"];
searchVC.modalInPopover = NO;
UINavigationController* contentViewController = [[UINavigationController alloc] initWithRootViewController:searchVC];
popoverController = [[WYPopoverController alloc] initWithContentViewController:contentViewController];
popoverController.delegate = self;
//popoverController.passthroughViews = #[btn];
popoverController.popoverContentSize = CGSizeMake(width, height);
popoverController.popoverLayoutMargins = UIEdgeInsetsMake(10, 10, 10, 10);
popoverController.wantsDefaultContentAppearance = YES;
[popoverController presentPopoverFromBarButtonItem:btn permittedArrowDirections:WYPopoverArrowDirectionAny animated:YES];
}
And this is the didSelctRow method (SearchViewController.m) :
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main"bundle:nil];
PostReaderViewController *postReaderView =
(PostReaderViewController *)
[storyboard instantiateViewControllerWithIdentifier:#"postReader"];
postReaderView.thePost = [_postsArray objectAtIndex:indexPath.row];
// if ([self.parentViewController.po .popoverController isPopoverVisible])
// [popoverController dismissPopoverAnimated:YES];
[self.navigationController pushViewController:postReaderView animated:YES];
}
To solve this issue I've passed the Navigation controller and popoverController from The parent View MainVC.h to child controller SearchViewController.h and then use those vars to dismiss my PopOvercontroller and push the new VC. Code snippet :
SearchView
#interface SearchViewController : UIViewController
#property (strong, nonatomic) WYPopoverController *parentPopoverVC;
#property (strong, nonatomic) UINavigationController *parentNavigationController;
#end
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
...
[self.parentPopoverVC dismissPopoverAnimated:YES];
[self.parentNavigationController pushViewController:postReaderView animated:YES];
}
MainVC.h
-(IBAction)showPopoverSearch:(id)sender{
SearchViewController *searchVC = [self.storyboard instantiateViewControllerWithIdentifier:#"searchView"];
[searchVC setParentPopoverVC:popoverController];
[searchVC setParentNavigationController:self.navigationController];
[popoverController presentPopoverFromBarButtonItem:btn permittedArrowDirections:WYPopoverArrowDirectionAny animated:YES];
}
I have a custom class (FFFuelQuantityPickerVC) Storyboard View Controller that contains a UIPickerView and a UIButton. The UIButton is wired to an IBAction called fullButtonPressed in FFFuelQuantityPickerVC. When this View Controller is presented using a storyboard popover segue, the fullButtonPressed IBAction is fired when the UIButton is "touched up inside."
However, when I programmatically init and present FFFuelQuantityPickerVC in a popup, pressing the UIButton does not fire the IBAction. Why would that be? Here is the code that does the programmatic presentation when a button in a UITableViewCell is pressed. (self.poc is a reusable popover controller):
-(void)thisHelperPressed:(UIButton *)thisHelper inCell:(UITableViewCell *)thisCell{
if ([thisHelper.titleLabel.text isEqualToString:#"FuelPicker"]){
//init the fuel quantity picker VC
FFFuelQuantityPickerVC *fuelQuantityPickerVC;
fuelQuantityPickerVC =[[UIStoryboard storyboardWithName:#"MainStoryboard"
bundle:nil]
instantiateViewControllerWithIdentifier:#"FuelQuantityPickerVC"];
fuelQuantityPickerVC.delegate = self;
[self.poc setContentViewController:fuelQuantityPickerVC];
} else if...
}
self.poc.delegate = self;
//present it
[self.poc presentPopoverFromRect:thisHelper.frame inView:thisCell permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
.
.
.
Here is FFFuelQuantityPickerVC:
// FFFuelQuantityPickerVC.h
#import <UIKit/UIKit.h>
#protocol fuelPickerDelegate <NSObject>
-(void) fuelQuantityChangedL:(NSInteger) quantityL R:(NSInteger)quantityR;
#end
#interface FFFuelQuantityPickerVC : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>
#property (weak, nonatomic) IBOutlet UIPickerView *thisPicker;
#property (nonatomic) NSString *fuelQuantityL;
#property (nonatomic) NSString *fuelQuantityR;
#property (nonatomic) id delegate;
- (IBAction)fullButtonPressed; //this is wired to the button
#end
//
// FFFuelQuantityPickerVC.m
#import "FFFuelQuantityPickerVC.h"
#define FUEL_MIN 0
#define FUEL_MAX 146
#define LEFT_COMPONENT 0
#define RIGHT_COMPONENT 1
#interface FFFuelQuantityPickerVC ()
#end
#implementation FFFuelQuantityPickerVC
- (void)viewDidLoad
{
[super viewDidLoad];
if (!self.fuelQuantityL){
self.fuelQuantityL = [NSString stringWithFormat:#"%i", FUEL_MAX];
}
if (!self.fuelQuantityR){
self.fuelQuantityR = [NSString stringWithFormat:#"%i", FUEL_MAX];
}
}
//set selected row to current values, if any
- (void) viewDidAppear:(BOOL)animated {
[self.thisPicker selectRow:FUEL_MAX - [self.fuelQuantityL intValue] inComponent:LEFT_COMPONENT animated:YES];
[self.thisPicker selectRow:FUEL_MAX - [self.fuelQuantityR intValue] inComponent:RIGHT_COMPONENT animated:YES];
}
//this method does not get called when the button is pressed (except when the VC is presented via storyboard popover segue)
- (IBAction)fullButtonPressed {
self.fuelQuantityL = [NSString stringWithFormat:#"%i", FUEL_MAX];
self.fuelQuantityR = [NSString stringWithFormat:#"%i", FUEL_MAX];
[self.thisPicker selectRow:0 inComponent:0 animated:YES];
[self.thisPicker selectRow:0 inComponent:1 animated:YES];
[self.delegate fuelQuantityChangedL:[self.fuelQuantityL integerValue]
R:[self.fuelQuantityR integerValue]];
}
#pragma mark - PickerViewDataSource delegate methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return (FUEL_MAX-FUEL_MIN + 1);
}
#pragma mark - PickerView delegate methods
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{
float myWidth = self.view.frame.size.width;
if (component == 0) return myWidth / 3;
return (myWidth * 2 / 3);
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
//TODO
return 28;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [NSString stringWithFormat:#"%d", (FUEL_MAX)-row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
if (component == LEFT_COMPONENT){
self.fuelQuantityL = [NSString stringWithFormat:#"%i", FUEL_MAX - row];
} else {
self.fuelQuantityR = [NSString stringWithFormat:#"%i", FUEL_MAX - row];
}
[self.delegate fuelQuantityChangedL:[self.fuelQuantityL integerValue]
R:[self.fuelQuantityR integerValue]];
}
#end
Here is my code. I m using this code for display the UIPopoverController when I click the cell and pick the value from UIPickerView to display the value in UILabel in my UITableviewCell
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0)
{
if (indexPath.row == 1)
{
//PopoverView controller.........................................................................
UIViewController *popoverViewController = [[UIViewController alloc] init];
//PopoverView....................................................................................
UIView *popoverView = [[UIView alloc]init];
[popoverView setBackgroundColor:[UIColor blackColor]];
//Navigation bar and Barbutton items..............................................................
UINavigationBar *navBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
navBar.barStyle = UIBarStyleBlackTranslucent;
UIBarButtonItem *btnDone = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(doDone)];
UIBarButtonItem *btnCancel = [[UIBarButtonItem alloc]initWithTitle:#"Cancel" style:UIBarButtonItemStylePlain target:self action:#selector(doCancel)];
UINavigationItem *navItem = [[UINavigationItem alloc]init];
navItem.rightBarButtonItem = btnDone;
navItem.leftBarButtonItem = btnCancel;
navBar.items = [[NSArray alloc]initWithObjects:navItem, nil];
[popoverView addSubview:navBar];
//UIPickerView.....................................................................................
UIPickerView *sortPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 50, 320, 180)];
popoverViewController.contentSizeForViewInPopover = CGSizeMake(320, 230);
sortPickerView.delegate = self;
sortPickerView.dataSource = self;
sortPickerView.showsSelectionIndicator = YES;
[popoverView addSubview:sortPickerView];
NSUserDefaults *ud1 = [NSUserDefaults standardUserDefaults];
if ([ud1 objectForKey:#"languages"])
{
NSUInteger row1 = [languages indexOfObject:[ud1 objectForKey:#"languages"]];
if (row1)
{
[sortPickerView selectRow:row1 inComponent:0 animated:YES];
}
}
else
{
[sortPickerView selectRow:0 inComponent:0 animated:YES];
}
CGRect popFrame = lbl_language.frame;
popFrame.origin.y = popFrame.origin.y + popFrame.size.height + 70;
popFrame.origin.x = popFrame.origin.x + 100;
popoverViewController.view = popoverView;
self.SortPopover = [[UIPopoverController alloc] initWithContentViewController:popoverViewController];
[self.SortPopover presentPopoverFromRect:popFrame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
}
For reasons that are unclear to me, the UI Button was not receiving the push - it never highlighted. It was not overlaid by another view that I could see (the only other view was the picker). Anyway, I added a UIToolbar and changed the button to a bar button item and it works fine.
I need enlightenment with my view controllers. The first view controller has a UILabel and a UIButton. The UIButton leads to the second view controller.
The second view controller is a UITableView. Everything in this view is done programmatically including the UINavigationBar, UINavigationItem, and the UIBarButtonItem. It has NO UINavigationController.
So once a user selects a currency from the list, it should update the UILabel in the first view controller. But it won't.
first view controller .h:
#import <UIKit/UIKit.h>
#import "CurrencyListViewController.h"
#interface InformationViewController : UIViewController <CurrencyListViewControllerDelegate>
#property (nonatomic, retain) IBOutlet UILabel *currencyLabel;
- (IBAction)currencyButton;
#end
first view controller .m:
- (void)viewDidLoad
{
[super viewDidLoad];
[self createCurrencyButton];
[self createAcceptDeclineButton];
[self createCurrencyLabel];
}
- (IBAction)currencyButton
{
CurrencyListViewController *currencyView = [[CurrencyListViewController alloc] initWithNibName:#"CurrencyListViewController" bundle:nil];
currencyView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
currencyView.delegate = self;
[self presentViewController:currencyView animated:YES completion:nil];
}
- (void)createCurrencyLabel
{
currencyLabel = [[UILabel alloc] initWithFrame:CGRectMake(100.0, 100.0, 120.0, 40.0)];
currencyLabel.hidden = NO;
currencyLabel.textColor = [UIColor whiteColor];
currencyLabel.textAlignment = NSTextAlignmentCenter;
[currencyLabel setEnabled:NO];
[self.view addSubview:currencyLabel];
}
- (void)currencySelected: (NSString *)currencySelected
{
currencyLabel.text = [NSString stringWithFormat:#"%#", currencySelected];
NSLog(#"Current currency is %#", currencyLabel.text);
}
second view controller .h:
#import <UIKit/UIKit.h>
#protocol CurrencyListViewControllerDelegate <NSObject>
- (void)currencySelected: (NSString *)currencySelected;
#end
#interface CurrencyListViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> {
id<CurrencyListViewControllerDelegate> delegate;
}
#property (nonatomic, retain) UITableView *tableView;
#property (nonatomic, assign) id delegate;
#end
second view controller .m:
- (void)viewDidLoad
{
[super viewDidLoad];
UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:#"Currency"];
UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithTitle: #"Cancel"
style:UIBarButtonItemStylePlain
target:self
action:#selector(cancelButtonPressed:)];
navigationItem.rightBarButtonItem = barItem;
UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 44.0, self.view.frame.size.width, self.view.frame.size.height - navigationBar.frame.size.height) style:UITableViewStylePlain];
self.tableView = tableView;
[navigationBar pushNavigationItem:navigationItem animated:NO];
[self.view addSubview:tableView];
[self.view addSubview:navigationBar];
[self showCurrencies];
self.tableView.dataSource = self;
self.tableView.delegate = self;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [arrayOfCurrencies objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
InformationViewController *informationViewController = [[InformationViewController alloc] init];
if ([_delegate respondsToSelector:#selector(currencySelected:)]) {
informationViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[_delegate currencySelected:[arrayOfCurrencies objectAtIndex:indexPath.row]];
NSLog(#"The user selects %#", [arrayOfCurrencies objectAtIndex:indexPath.row]);
}
[self presentViewController:informationViewController animated:YES completion:nil];
}
I am able to output:
2013-06-05 00:16:58.731 Testing[7056:c07] Current currency is AOA: Angolan Kwanza
2013-06-04 19:08:27.222 Testing[3613:c07] 2013-06-05 00:16:58.732 Testing[7056:c07] The user selects AOA: Angolan Kwanza
But the UILabel in my first view controller will NOT.
Why are presenting informationViewController again? dismiss the Current ViewController, which is CurrencyListViewController and do the currencySelected function
Should look like this:
[self dismissModalViewControllerAnimated:YES];
[_delegate currencySelected:[arrayOfCurrencies objectAtIndex:indexPath.row]];
I'm trying to get a GUI with a UITabBar and UITableViews set up.
I've got a UITabView that is programmatically created.
One of the Tabs displays a UITableView that is also programmatically created.
This UITableView then displays other views when didSelectRowAtIndexPath is called.
Unfortunately, when a table cell is clicked, my tab view goes away and the new table view is displayed.
What I can't get my head around is how to structure the views so that the tabBar stays on the screen.
Is it as simple as making the UITableViews shorter, or is there some window/view mojo that I'm missing?
Thanks
You should use a UITabBarController to display the UITabBar rather than doing it directly.
Then use a UITableViewController as the view controller for a given tab. Though I get the impression that you want to present descendent UITableViews when a row is selected. If this is the case, you ought to use a UINavigationController as the tab bar's view controller, and let it manage your UITableViewControllers.
Remember that on iOS you really need to use the view controller pattern - the frameworks take care of a lot of things for you under the hood.
Follow-up:
OK, the following straightforward implementation works just fine for me. Please ignore the many obvious issues with this code (beginning with the fact that I hacked it all together in the application delegate!); it's intended purely as a model for how your controllers should be glued together.
#import <UIKit/UIKit.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate, UITableViewDelegate, UITableViewDataSource>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) UINavigationController *navController;
#end
#implementation AppDelegate
#synthesize window = _window;
#synthesize navController = _navController;
- (void)dealloc
{
[_navController release];
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UITableViewController *rootTVC = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
[[rootTVC tableView] setDelegate:self];
[[rootTVC tableView] setDataSource:self];
[rootTVC setTitle:#"Root Table"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootTVC];
[rootTVC release];
[navController setTitle:#"My Table"];
UIViewController *anotherViewController = [[UIViewController alloc] init];
[anotherViewController setTitle:#"Not the table"];
UITabBarController *tbc = [[UITabBarController alloc] init];
[tbc setViewControllers:[NSArray arrayWithObjects:navController, anotherViewController, nil]];
[self setNavController:navController];
[navController release];
[anotherViewController release];
[[self window] setRootViewController:tbc];
[tbc release];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *reuseIdentifier = #"foo";
UITableViewCell *cell = [[tableView dequeueReusableCellWithIdentifier:reuseIdentifier] retain];
if (! cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
}
[[cell textLabel] setText:[NSString stringWithFormat:#"Row %d", [indexPath row]]];
return [cell autorelease];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewController *newTVC = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
[newTVC setTitle:[NSString stringWithFormat:#"Table %d", [indexPath row]]];
[[newTVC tableView] setDelegate:self];
[[newTVC tableView] setDataSource:self];
[[self navController] pushViewController:newTVC animated:YES];
}
#end
Use UITabBarController instead of UITabBar.
I am using Apple's MuiltipleDetailViewController sample app and get the message "UIViewController may not respond to showRootPopoverButtonItem"
This worked in XCode 3.X, but I get the message with 4.2
The app itself functions 100%, the popover is recognized in every nib, as is the table on the left when in landscape mode. But I can't submit with this warning. What do I need to change??
RootViewController.h
#import <UIKit/UIKit.h>
/*
SubstitutableDetailViewController defines the protocol that detail view controllers must adopt. The protocol specifies methods to hide and show the bar button item controlling the popover.
*/
#protocol SubstitutableDetailViewController <NSObject>
- (void)showRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem;
- (void)invalidateRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem;
#end
#interface RootViewController : UITableViewController <UISplitViewControllerDelegate> {
UISplitViewController *splitViewController;
UIPopoverController *popoverController;
UIBarButtonItem *rootPopoverButtonItem;
//UINavigationBar *navigationBar;
}
#property (nonatomic, assign) IBOutlet UISplitViewController *splitViewController;
#property (nonatomic, retain) UIPopoverController *popoverController;
#property (nonatomic, retain) UIBarButtonItem *rootPopoverButtonItem;
//#property (nonatomic, retain) IBOutlet UINavigationBar *navigationBar;
#end
RootViewController.m:
#import "RootViewController.h"
#import "WebViewController.h"
#import "Twitter.h"
//#import "SubstitutableDetailViewController.h"
#implementation RootViewController
#synthesize splitViewController, popoverController, rootPopoverButtonItem;//, navigationBar;
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
// Set the content size for the popover: there are just two rows in the table view, so set to rowHeight*2.
self.contentSizeForViewInPopover = CGSizeMake(310.0, self.tableView.rowHeight*2.0);
//self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:255/255 green:104/255 blue:1/255 alpha:1];
}
/*
-(void)customizeAppearance {
//create resizable images
UIImage *bluImage = [UIImage imageNamed:#"blu.jpg"];// resizableImageWithCapInsets:(0, 0, 0, 0)];
//set the bg for *all* UINavBars
[[UINavigationBar appearance] setBackgroundImage:bluImage forBarMetrics:UIBarMetricsDefault];
}
*/
-(void) viewDidUnload {
[super viewDidUnload];
self.splitViewController = nil;
self.rootPopoverButtonItem = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)splitViewController:(UISplitViewController*)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem*)barButtonItem
forPopoverController:(UIPopoverController*)pc {
// Keep references to the popover controller and the popover button, and tell the detail view controller to show the button.
barButtonItem.title = #"Index";
self.popoverController = pc;
self.rootPopoverButtonItem = barButtonItem;
UIViewController <SubstitutableDetailViewController> *detailViewController = [splitViewController.viewControllers objectAtIndex:1];
[detailViewController showRootPopoverButtonItem:rootPopoverButtonItem];
}
- (void)splitViewController:(UISplitViewController*)svc willShowViewController:(UIViewController *)aViewController
invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem {
// Nil out references to the popover controller and the popover button, and tell the detail view controller to hide the button.
UIViewController <SubstitutableDetailViewController> *detailViewController = [splitViewController.viewControllers objectAtIndex:1];
[detailViewController invalidateRootPopoverButtonItem:rootPopoverButtonItem];
self.popoverController = nil;
self.rootPopoverButtonItem = nil;
}
#pragma mark -
#pragma mark Table view data source
- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section {
// Two sections, one for each detail view controller.
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"RootViewControllerCellIdentifier";
// Dequeue or create a cell of the appropriate type.
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
//cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Set appropriate labels for the cells.
if (indexPath.row == 0) {
cell.textLabel.text = #"Twitter";
}
else if (indexPath.row == 1) {
cell.textLabel.text = #"Contact Us";
}
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.backgroundColor = [UIColor blackColor];
cell.contentView.backgroundColor = [UIColor blackColor];
cell.detailTextLabel.backgroundColor = [UIColor blackColor];
return cell;
}
#pragma mark -
#pragma mark Table view selection
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
/*
Create and configure a new detail view controller appropriate for the selection.
*/
NSUInteger row = indexPath.row;
UIViewController *detailViewController = nil;
if (row == 0) {
Twitter *newDetailViewController = [[Twitter alloc]
initWithNibName:#"Twitter"
bundle:nil];
detailViewController = newDetailViewController;
}
if (row == 1) {
WebViewController *newDetailViewController = [[WebViewController alloc]
initWithNibName:#"WebViewController"
bundle:nil];
newDetailViewController.detailURL=
[[NSURL alloc] initWithString:#"http://www.chipmunkmobile.com/contact.html"];
detailViewController = newDetailViewController;
}
// Update the split view controller's view controllers array.
NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, detailViewController, nil];
splitViewController.viewControllers = viewControllers;
[viewControllers release];
// Dismiss the popover if it's present.
if (popoverController != nil) {
[popoverController dismissPopoverAnimated:YES];
}
// Configure the new view controller's popover button (after the view has been displayed and its toolbar/navigation bar has been created).
if (rootPopoverButtonItem != nil) {
[detailViewController showRootPopoverButtonItem:self.rootPopoverButtonItem];
}
[detailViewController release];
}
#pragma mark -
#pragma mark Managing the popover
/*
- (void)showRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem {
// Add the popover button to the left navigation item.
[navigationBar.topItem setLeftBarButtonItem:barButtonItem animated:NO];
}
- (void)invalidateRootPopoverButtonItem:(UIBarButtonItem *)barButtonItem {
// Remove the popover button.
[navigationBar.topItem setLeftBarButtonItem:nil animated:NO];
}
*/
#pragma mark -
#pragma mark Memory management
- (void)dealloc {
[popoverController release];
[rootPopoverButtonItem release];
[super dealloc];
}
#end
Here is an image of the exact line where I get the warning
The reason you getting this warning is because of this UIViewController *detailViewController UIViewController does not have a method called "showRootPopoverButtonItem". If you want to get rid of the warning just do this instead:
[(WebViewController*)detailViewController showRootPopoverButtonItem:self.rootPopoverButtonItem];
or
[(Twitter*)detailViewController showRootPopoverButtonItem:self.rootPopoverButtonItem];
You just need to let it know its not really just a viewController, its a subclassed viewController you created. So what ever class showRootPopoverButtonItem: is in you just need to type cast it.
If you want to leave your code exactly the same but get rid of the warning you can do this.
if (rootPopoverButtonItem != nil) {
[detailViewController performSelector:#selector(showRootPopoverButtonItem:) withObject:self.rootPopoverButtonItem];
}
If you want to be more careful you should use this.
if (rootPopoverButtonItem != nil && [detailViewController respondsToSelector:#selector(showRootPopoverButtonItem:)]) {
[detailViewController performSelector:#selector(showRootPopoverButtonItem:) withObject:self.rootPopoverButtonItem];
}
Update
After reading through your code you could just specify the delegate on the detailViewController like you did in the other functions.
UIViewController<SubstitutableDetailViewController> *detailViewController = nil;
if (row == 0) {
//...
(1)Specify the Type for the detailedViewController: [(TYPE *)OBJECTNAME...
(2) Then Specify method call [(TYPE *)OBJECTNAME METHODCALL];
(*) You get the warning because the compiler does not know what type of object you are using. If you subclass a UIViewController then you have to specify type when accessing methods.Make sure the method is in .h so that you can access it.