can not setimage of uiimageview while pushing viewcontroller - iphone

I am new on objective c and I am trying to set image of UIImageview while pushing viewcontroller
I checked other answer and I did the same way they said it but its not working for me below is my code and i will explain other things in it
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *svController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:[NSBundle mainBundle]];
UIImage *image = [UIImage imageNamed:#"default.png"];
UIImageView* imageview = [[UIImageView alloc] initWithImage:image];
id obj = [[mainArray valueForKey:#"image"] objectAtIndex:[indexPath row]];
if ([obj isKindOfClass:[NSString class]])
{
NSLog(#" image%#",image); //print this image<UIImage: 0xaa70700>
NSLog(#" image%#",svController.image); //print this image(null)
[[svController image] setImage: image];
NSLog(#" image%#",svController.image); //print this image(null)
}
else {
NSLog(#" image%#",svController.image);
[[svController image] setImage: [[mainArray valueForKey:#"image"] objectAtIndex:[indexPath row]]];
NSLog(#" image%#",svController.image);
}
[self.navigationController pushViewController:svController animated:YES];
[svController release];
svController = nil;
}
below is my detailviewcontroller
#interface DetailViewController : UIViewController{
UIImageView *image;
}
#property (retain, nonatomic) IBOutlet UIImageView *image;
its connected to Xib and i have synthesized it
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
name.text = nameString;
email.text = emailString;
NSLog(#"%#",image); // print this <UIImageView: 0x9d73950; frame = (27 35; 204 181); autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x9db4050>>
}
its working perfectly when i send NSString and set them on my lable but not working for image it its so small thing but now i dont know what to do please help

hear is the simple way, i am showing the example that u can set image in detail view controller
in your master view controller
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == 0)//for 1st row
{
DetailViewController *detController = [[DetailViewController alloc]initWithNibName:#"DetailViewController" bundle:nil];
detController.detailImage = [UIImage imageNamed:#"abc.png"];//setting the property for image
[self.navigationController pushViewController:detController animated:YES];
[detController release];//im doing without ARC
}
else if (indexPath.row == 1)
{
DetailViewController *detController = [[DetailViewController alloc]initWithNibName:#"DetailViewController" bundle:nil];
detController.detailImage = [UIImage imageNamed:#"123.png"];
[self.navigationController pushViewController:detController animated:YES];
[detController release];//im doing without ARC
}
}
and in your detail view controller
// .h file
#interface DetailViewController : UIViewController
{
}
#property (retain, nonatomic) IBOutlet UIImageView *ImageView;
#property (nonatomic, retain)UIImage * detailImage;//set a property for image that u are passing from master viewcontroller
#end
//in .m file
#implementation DetailViewController
#synthesize detailImage; //synthesise it
// and in viewDidload method
- (void)viewDidLoad
{
[super viewDidLoad];
//set your passed image to image view
self.ImageView.image = self.detailImage;
}
Better would be just do like this:
[self.navigationController pushViewController:svController animated:YES];
if(yourImage) //got UIImage reference then only set it
svController.yourImgView.image = yourImageHere
.................
<<Another code here>>
..............
Thats it....

You can't do this, because svController's view has not been loaded at the time you try to set the image of its image view (so the image view will be null).
You need to pass the image itself to a property you create in svController, and set the image in svController's viewDidLoad method.

Set your UI object intialization afer pushing view controller.
[self.navigationController pushViewController:svController animated:YES];
//set image here
Reason is viewDidLoad of svController will not be called and loaded yet and imageview will not have reference yet.
EDIT :
Better would be just do like this:
[self.navigationController pushViewController:svController animated:YES];
if(yourImage) //got UIImage reference then only set it
svController.yourImgView.image = yourImageHere
.................
<<Another code here>>
..............
Thats it....

Related

getting content from plist to UITableView to details view controller

Im trying to get the label and images of each item in my plist library to show up in my details tab.
Here is a pic of my tableview which i can get my plist dictionary to work. An array of images and an array or items. (ex item 0 is both the thermostat.jpg and Thermostat label.
Here is a pic of the detail view when clicking on the cell. It pulls the label from the cell and the image of the thermostat.
However when clicking on item 1 in plist (the toilet) it pulls the toilet name but still shows the thermostat image. Like so.
Here is my code for detailviewcontroller
the.h
#import <Foundation/Foundation.h>
#interface DetailViewController : UIViewController
{
IBOutlet UIScrollView *scrollView;
}
#property (nonatomic, strong) IBOutlet UILabel *itemLabel;//Name of that view
#property (nonatomic, strong) NSString *itemName;
#property (nonatomic, strong) IBOutlet UIImageView *myImageView; //Image View
#property (strong, nonatomic) IBOutlet UILabel *myTextView; //Description View
#end
and .m
#import "DetailViewController.h"
#interface DetailViewController ()
#end
#implementation DetailViewController
#synthesize itemLabel;
#synthesize itemName;
#synthesize myImageView;
#synthesize myTextView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
itemLabel.text = itemName;
//**************SCROLL VIEW*************
[scrollView setScrollEnabled:YES];
[scrollView setContentSize:CGSizeMake(320,960)];
scrollView.contentInset=UIEdgeInsetsMake(0.0,0.0,90.0,0.0);
////I know below this is the Problem, BUT im not sure what its supposed to be?////
NSDictionary *picturesDictionary = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"repairlist" ofType:#"plist"]];
NSArray *imageArray = [picturesDictionary objectForKey:#"Thumbnail"];
myImageView.image = [UIImage imageNamed:[imageArray objectAtIndex:0]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
So all in all im trying to get the image to correctly show when clicking on that cell
Here is an image of my plist im using:
I already have this in my TableViewController
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"ItemListCell"]) {
DetailViewController *destViewController = segue.destinationViewController;
NSIndexPath *indexPath = nil;
if ([self.searchDisplayController isActive]) {
indexPath = [self.searchDisplayController.searchResultsTableView indexPathForSelectedRow];
destViewController.itemName = [searchResults objectAtIndex:indexPath.row];
} else {
indexPath = [self.myTableView indexPathForSelectedRow];
destViewController.itemName = [repairList objectAtIndex:indexPath.row];
//destViewController.textView = [descrip objectAtIndex:indexPath.row];
}
}
}
Here is your problem,
myImageView.image = [UIImage imageNamed:[imageArray objectAtIndex:0]];
You set your image always the same index which is 0. So, logically, you're always seeing the same image. So, what you need to is that you need to detect which cell was selected before you push DetailViewController and pass that info to your DetailViewController. Then, you need to use that info to show appropriate image in your DetailViewController.
First, you need to declare a property in DetailViewController.h,
#property int selectedRow;
change also this line of code
myImageView.image = [UIImage imageNamed:[imageArray objectAtIndex:0]];
to
myImageView.image = [UIImage imageNamed:[imageArray objectAtIndex:self.selectedRow]];
Then in your TableViewController.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"YourSegueIdentifier"]) {
NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
DetailViewController *detailViewController = [segue destinationViewController];
detailViewController.selectedRow = [dataController objectInListAtIndex:selectedRowIndex.row];
}
}

iOS UITableView not displayed

I have inherited some old iOS code and have attempted to integrate it into a new iOS 6 application. I have implemented most of the code and so far everything has worked. I'm now working on the last bit of that old code. I'm implementing a set of views to show a rss for a news section of my app. I've implemented the categories view, which upon selecting an item would display the individual items within that category. However nothing gets displayed. I've made all the modifications that I'm aware of that I needed to do, however I'm no expert at iOS development and am in need of some guidance. Below is a snapshot of the simulator as it's attempting to display the view, and below that is a copy of my .h and .m files. I don't know what is preventing anything in the table from showing up. And preemptive thanks to any help!
here's the snapshot of the simulator
Here is a snapshot of the storyboard showing the linking to the Table View
Here's the .h file
#import <UIKit/UIKit.h>
#import "BlogRssParser.h"
#class BlogRssParser;
#class BlogRssParserDelegate;
#class BlogRss;
#class XMLCategory;
#interface NewsViewController : UIViewController <UITableViewDataSource,UITableViewDelegate, BlogRssParserDelegate> {
BlogRssParser * _rssParser;
XMLCategory * _currItem;
}
#property (nonatomic, retain) BlogRssParser * rssParser;
#property (readwrite, retain) XMLCategory * currItem;
#property (nonatomic, retain) IBOutlet UITableView *itemTableView;
#end
Here is my .m file
#import "NewsViewController.h"
#import "NewsDetailsViewController.h"
#import "BlogRssParser.h"
#import "BlogRss.h"
#import "XMLCategory.h"
#define kLabelTag 1;
#interface NewsViewController ()
#end
#implementation NewsViewController
#synthesize rssParser = _rssParser;
#synthesize currItem = _currItem;
- (void)navBarInit {
UIBarButtonItem *refreshBarButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self action:#selector(reloadRss)];
[self.navigationItem setRightBarButtonItem:refreshBarButton animated:YES];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.itemTableView.delegate = self;
self.itemTableView.dataSource = self;
- (void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self navBarInit];
[self.itemTableView reloadData];
self.itemTableView.userInteractionEnabled = NO;
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
_rssParser = [[BlogRssParser alloc]init];
_rssParser.delegate = self;
[[self rssParser]startProcess:[_currItem categoryId]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)reloadRss{
[[self rssParser]startProcess:[_currItem categoryId]];
[[self itemTableView]reloadData];
}
- (void)processCompleted{
[[self itemTableView]reloadData];
// _tableView.userInteractionEnabled = YES;
[[self itemTableView]setUserInteractionEnabled:YES];
}
-(void)processHasErrors{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"My Title" message:#"Unable to retrieve the news. Please check if you are connected to the internet."
delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [[[self rssParser]rssItems]count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
const CGFloat LABEL_TITLE_HEIGHT = 70.0;
const CGFloat LABEL_WIDTH = 210.0;
NSString * mediaUrl = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]mediaUrl];
NSData * imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mediaUrl]];
UIImage * imageFromImageData;
if (imageData == nil) {
imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:#"http://www.urlForImage.image.png"]];
}
imageFromImageData = [[UIImage alloc] initWithData:imageData];
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:#"rssItemCell"];
if(nil == cell){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"rssItemCell"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UILabel * _topLabel =
[[UILabel alloc]
initWithFrame:
CGRectMake(
imageFromImageData.size.width + 10.0,
0.0,
LABEL_WIDTH,
LABEL_TITLE_HEIGHT)];
_topLabel.tag = kLabelTag;
_topLabel.opaque = NO;
_topLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
_topLabel.backgroundColor = [UIColor clearColor];
_topLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
_topLabel.highlightedTextColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.9 alpha:1.0];
_topLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]];
_topLabel.numberOfLines = 0;
[cell.contentView addSubview:_topLabel];
}
cell.imageView.image = imageFromImageData;
UILabel * topLabel = (UILabel *)[cell.contentView viewWithTag:1];
topLabel.text = [[[[self rssParser]rssItems]objectAtIndex:indexPath.row]title];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NewsDetailsViewController *tlc = [[DetailsViewController alloc]init];
tlc.currentItem = [[[self rssParser]rssItems]objectAtIndex:indexPath.row];
tlc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:tlc animated:YES completion:nil];
}
#end
I could not get a conclusion about the problem you are facing.
But here are few things you should check.
Because i cannot see even an empty table view in your screenshot
Do you have the TableView on the Nib file ?
It is mapped from The Nib file to the IBOutlet itemTableView ?
Add at least one table view cell (Drag and drop one prototype cell)..
like this
Then select that cell and give some name in "Reuse Identifier" with this identifier allow datasource..
First thing I would do is make sure that [[[self rssParser] rssItems] count] is actually returning > 0. Also, is this a copy&paste of your .m file? viewDidLoad is missing the closing brace, but Xcode would catch that.

Dismiss UIPopoverController on didSelectRowAtIndexPath

I have implemented UIPopoverController with storyboard but i am not able to make it dismiss when I select particular row in UITableView.
When select particular row so that time I want to dismiss the popover but I am not able dismiss it.
I write below code for this:
//Show the popover in Main UIViewController
-(IBAction)clickNotes:(id)sender {
NSLog(#"notes:");
NoteList *objNoteList = [[NoteList alloc] initWithNibName:#"NoteList" bundle:nil];
popover.delegate = self;
popover = [[UIPopoverController alloc] initWithContentViewController:objNoteList];
popover.popoverContentSize = CGSizeMake(250, 450);
[popover presentPopoverFromRect:CGRectMake(730, 0, 1,1) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
//Hide the popover in another UIViewController on didSelecteRowAtIndexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Notepad_ipad *objNote = [[Notepad_ipad alloc] init];
NSString *mSelectedNoteText = #"Selected text";
[objNote SelectedNote:mSelectedNoteText];
[objNote.popover dismissPopoverAnimated:YES];
}
use
[popover dismissPopoverAnimated:YES];
The following code instantiates a NEW Instance. So it has nothing to do with the already existing popover :Notepad_ipad *objNote = [[Notepad_ipad alloc] init];
Also Instead Of :
popover.delegate = self;
popover = [[UIPopoverController alloc] initWithContentViewController:objNoteList];
USE:
popover = [[UIPopoverController alloc] initWithContentViewController:objNoteList];
popover.delegate = self;
I.e.: Allocate the instance first and then set its delegate.
Finally replace your method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
with this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *) indexPath {
[popover dismissPopoverAnimated:YES];
}
// Create protocol in .h file of controller which contains didSelectRowAtIndexPath method as follows:
#protocol Popoverdelegate <NSObject>
{
-(void)didRowAtIndexPathIsSelected;
}
// Add this property in .h file of the same controller
#property (strong, nonatomic) id<Popoverdelegate> delegate;
// Now implement this protocol in interface which calls popovercontroller
// for ex: #interface ViewController <Popovercontroller>
// then add following properties to viewController .h file
#protocol (strong, nonatomic) UIPopoverController *popoverController;
// Implement popoverdelegate protocol in .m file as
- (void) didRowAtIndexPathIsSelected
{
[self.popoverController dismissPopoverAnimated:YES];
}
// Replace your code as follows
-(IBAction)clickNotes:(id)sender
{
NoteList *objNoteList = [[NoteList alloc] initWithNibName:#"NoteList" bundle:nil];
popover = [[UIPopoverController alloc] initWithContentViewController:objNoteList];
popover.delegate = self;
self.popoverController = popover;
self.popoverController.popoverContentSize = CGSizeMake(250, 450);
[self.popoverController presentPopoverFromRect:CGRectMake(730, 0, 1,1) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Notepad_ipad *objNote = [[Notepad_ipad alloc] init];
NSString *mSelectedNoteText = #"Selected text";
[objNote SelectedNote:mSelectedNoteText];
[self.delegate dismissPopoverAnimated:YES];
}
The smartest thing to do here (imho) is to follow this example code, I do it every time:
// firstViewController.h
#interface firstViewController : UIViewController <SecondDelegate>
{
SecondViewController *choice;
}
// firstViewController.m
- (void)choicePicked(NSString *)choice
{
NSLog(choice);
[_popover dismissPopoverAnimated:YES]; //(put it here)
_popover = nil; (deallocate the popover)
_choicePicker = nil; (deallocate the SecondViewController instance)
}
// secondViewController.h (the one that will give back the data)
#protocol SecondDelegate <NSObject>
- (void)choicePicked:(NSString *)choice;
#end
#interface secondViewController : UITableViewController
#property (nonatomic, assign) id <SecondDelegate> delegate;
#end
// secondViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *selection = [_yourArray objectAtIndex:indexPath.row];
[[self delegate] choicePicked:selection];
}

How to push a new view tapping programmatically added UiImageViews in a custom cell

I want to make it so when I tap on an image in a UITableViewCell, it pushes a new view and displays an UIImageView that you can manipulate (such as pinching it and expanding it).
Currently, I'm using a custom cell which adds the image to the cell programmatically:
for (int i = 0; i < [self.news.imgURL count]; i++) {
UIImageView *image = [[UIImageView alloc] init];
[image setImageWithURL:[NSURL URLWithString:[self.news.imgURL objectAtIndex:i]]];
[image setFrame:CGRectMake(20, (labelSize.height + 25 + 14) + (i * 280), 280, 280)];
image.contentMode = UIViewContentModeScaleAspectFit;
image.tag = 101 + i;
image.userInteractionEnabled = YES;
[self.contentView addSubview:image];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap:)];
[tap setNumberOfTapsRequired:1]
[image addGestureRecognizer: tap];
}
This is located in my customcell.m file.
As seen in the code above, I use a GestureRecognizer that I can detect taps of the image using the following code:
-(void) handleTap:(UITapGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateEnded) {
NSLog(#"Image tapped!", nil);
}
}
But I have no idea how to push a new view from inside the customcell.m file. Is there a way to push a new view from inside the customcell.m file or must I explicitly do it from my masterviewcontroller?
This is a good use case for using a delegate. Define a delegate protocol for your custom cell class. Then have your table view controller set itself up as the cell's delegate. Your protocol should have a method that tells the delegate that an image was tapped. The cell and the image could be parameters of the delegate method.
In your cell's handleTap: method you can check if the delegate responds to the protocol method and if it does, it calls the protocol on the delegate, passing itself (the cell) and the tapped image.
write following code in cell tapped method or in didSelectRowAtIndexPath
yourViewCon *vc = [[yourViewCon alloc] init];
[self presentModalViewController:vc animated:YES];
First you setup a delegate in your MyCustomCell.h
#protocol MyCustomCellDelegate;
#interface MyCustomCell : UITableViewCell
#property (nonatomic, weak) id <MyCustomCellDelegate> delegate;
- (void)someCustomMethod:(NSString*)stringForChangingSomethingInMyCell;
#end
#protocol MyCustomDelegate <NSObject>
#required
- (void)itemTappedForRow:(NSUIInteger)rowNumber;
#end
In MyCustomCell.m, you synthesize the delegate:
#synthesize delegate = _delegate;
And in your handleTapMethod:
// You can use self.tag to track rowNumbers
[_delegate itemTappedForRow:rowNumber];
Meanwhile in your table view controller`, you conform to the protocol you just defined
#interface MyTableViewController : UITableViewController<MyCustomCellDelegate>
And you create the cells this way in your cellForRowAtIndexPath:
UITableViewCell *cell = [[MyCustomCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:#"yoBaby"];
cell.delegate = self;
cell.tag = indexPath.row;
return cell;
Finally, in itemTappedForRow, you push a new view controller that does the stuff for you. I'm assuming you are using a navigation controller.
[self.navigationController pushViewController:yourNewViewControllerWithTheImageSelected animated:YES];

MKMapView Annotation Callout Button to DetailView?

I have annotations in a MKMapView with Callouts. In this Callouts there's a "Right-Arrow" Button. When clicking on it, I want to open a Detail View, an extra UIViewController with its own nib file etc. I use following code:
In my MapViewController:
- (void)showDetails:(id)sender {
// the detail view does not want a toolbar so hide it
[self.navigationController setToolbarHidden:YES animated:NO];
NSLog(#"pressed!");
[self.navigationController pushViewController:self.detailViewController animated:YES];
NSLog(#"pressed --- 2!");
}
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(Annotation *) annotation {
if(annotation == map.userLocation) return nil;
static NSString* AnnotationIdentifier = #"AnnotationIdentifier";
MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
customPinView.pinColor = MKPinAnnotationColorRed;
customPinView.animatesDrop = YES;
customPinView.canShowCallout = YES;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self
action:#selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
customPinView.rightCalloutAccessoryView = rightButton;
UIImageView *memorialIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"googlemaps_pin.png"]];
customPinView.leftCalloutAccessoryView = memorialIcon;
[memorialIcon release];
return customPinView;
}
The button works, because when I give a NSLog inside the showDetais method, it's printed to the console. The problem is, that NOTHING happens. When clicking the button, it's like there isn't any button. There's no debug error or exception, just nothing.
the MapView header looks something like this:
#interface MapViewController : UIViewController <MKMapViewDelegate> {
MKMapView *map;
NSMutableDictionary *dictionary;
EntryDetailController *detailViewController;
}
#property (nonatomic,retain) IBOutlet MKMapView *map;
#property (nonatomic,retain) IBOutlet EntryDetailController *detailViewController;
Maybe someone of you can help me :)
Thanks!
Check if you have navigation controller for your viewController, if it is just a viewController then it cannot push a viewController because it does not have navigation controller in it.
I've had the same problem in the past and so I just used a different code to switch views:
-(IBAction)showDetails:(id)sender
{
NSLog(#"button clicked");
MapViewController *thisMap = (MapViewController *)[[UIApplication sharedApplication] delegate];
detailViewController *detailView = [[detailViewController alloc]initWithNibName:#"detailViewController" bundle:nil];
[thisMap switchViews:self.view toView:dvc.view];
}
It's a pretty basic view switching method and it works fine for me.
Isn't detailViewController uninitialized? You don't show all your code but I believe you might have things a bit jumbled up preparing the view and pushing it.
Why are you declaring the detailViewController as an IBOUTlet?
Also, I think you might want/intend to do this on your detailViewController not in this controller:
[self.navigationController setToolbarHidden:YES animated:NO];
You don't show all your code. But i guess, you just forget to initialise self.detailViewController.
try to add this in your viewDidLoad method:
self.detailViewController = [[[DetailViewController alloc]init]autorelease];