Why am I getting this error when loading my TableViewcontroller - iphone

I'm working on a project for iOS5 using ARC and storyboard.
I have a mapview with annotations with a disclosure button going to my DetailView (which is a TableViewController) but when it's supposed to be loaded, I get the following error:
2012-07-18 14:09:43.328 Zone-It-new[1966:707] Loadded the view for MapViewController
2012-07-18 14:11:40.467 Zone-It-new[1966:707] -[UILabel copyWithZone:]: unrecognized selector sent to instance 0x138470
2012-07-18 14:11:40.470 Zone-It-new[1966:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILabel copyWithZone:]: unrecognized selector sent to instance 0x138470'
*** First throw call stack:
(0x3748488f 0x35189259 0x37487a9b 0x37486915 0x373e1650 0x311997ef 0x31195059 0x31194711 0x3119466b 0x311945e7 0x31284f63 0x311979bb 0x311973ad 0x31191b8b 0x311917d5 0x9386d 0x3120a93d 0x31284627 0x37cf5933 0x37458a33 0x37458699 0x3745726f 0x373da4a5 0x373da36d 0x33b99439 0x31186cd5 0x924b3 0x92458)
terminate called throwing an exception(lldb)
This is my detailviewcontroller.h:
#import <UIKit/UIKit.h>
#import "Event.h"
#interface DetailViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>{
IBOutlet UILabel *title;
IBOutlet UILabel *description;
IBOutlet UILabel *zone;
IBOutlet UILabel *gemeente;
IBOutlet UILabel *plaats;
IBOutlet UILabel *deelnemers;
IBOutlet UILabel *start;
IBOutlet UILabel *einde;
IBOutlet UILabel *id_nr;
}
#property (nonatomic) Event *event;
#property (nonatomic) IBOutlet UILabel *title, *zone, *description, *gemeente, *deelnemers, *start, *einde, *plaats, *id_nr;
#end
part of the DetailViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[[self navigationController] setNavigationBarHidden:NO animated:YES];
/*title.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;*/
[title lineBreakMode];
[title setText:[event title]];
[title sizeToFit];
gemeente.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
[title lineBreakMode];
[gemeente setText:[event gemeente]];
}
And this is where the view gets created in via the ListView:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:#"detail"];
SingletonManager *sharedManager = [SingletonManager sharedManager];
[detail setEvent:[sharedManager.eventsManager objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:detail animated:YES];
}
Event.h
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
#interface Event : NSObject <MKAnnotation>
// required property from mkanotation
#property (nonatomic) CLLocationCoordinate2D coordinate;
// Optional
#property (nonatomic, copy) NSString *title;
#property (nonatomic, copy) NSString *description;
#property (nonatomic, copy) NSString *zone;
#property (nonatomic, assign) NSString *gemeente;
#property (nonatomic, copy) NSString *straat;
#property (nonatomic, assign) int deelnemers;
#property (nonatomic, copy) NSDate *start;
#property (nonatomic, copy) NSDate *einde;
#property (nonatomic, copy) NSString *plaats;
#property (nonatomic, readonly) int id_nr;
#property (nonatomic, assign) int huisnummer;
#end
----- Some more debugging information -------
While using the exception breakpoints it stopped here:
[self.navigationController pushViewController:detail animated:YES];
console:
2012-07-18 15:53:46.691 Zone-It-new[179:707] Loadded the view for MapViewController
2012-07-18 15:54:01.940 Zone-It-new[179:707] -[UILabel copyWithZone:]: unrecognized selector sent to instance 0x170bb0
(lldb)

It appears that somewhere in your code you're trying to copy a UILabel. UIView subclasses don't adhere to the NSCopying protocol, so trying to copy any UIView will result in an exception (unless it's a subclass that does implements the protocol). I'd search through your code base to check where the copy is occurring. If you can't find any place that explicitly copies the UILabel, check collection classes. Some collections classes will copy values in (NSDictionary does this with keys, so if you're trying to use a UILabel as a key for a NSDictionary, you'll get the error). Also check your properties. What you show in your displayed code is fine, but if you specify a copy in a protocol for a UILabel, that'll also give the error.
You should also try standard debugging techniques like setting a breakpoint for all exceptions. (go to the breakpoints nav pane, at the bottom click the plus sign). This should help you find the problem by breaking on your offending line of code. Just be aware that if the copying is occurring in Apple's code (like setting a NSDictionary key) the breakpoint might not break on your code.
Update
Given your new code, I would suggest trying the following:
Try to find any place in your code where "anything" is copied. Obviously your not explicitly copying UILabel but maybe you're accidentally copying it by passing the wrong argument somewhere. For example: Remove all copy keywords from your Event properties and test it again. You probably don't need to specify copy for NSString anyway, but what we're doing here is making sure you're not accidentally setting a UILabel to one of those properties. If the code doesn't break, you didn't fix it but now you know what the problem is (trying to assign a UILabel to the wrong property).
Start commenting out various blocks of code, one at a time, to find the problem. For example, comment out your entire viewDidLoad method and test your code. If it works, you know the problem is in there. So uncomment part of the method and test again. Keep repeating until you've narrowed down the problem. If it still breaks with viewDidLoad, uncomment that and try a different block of code. In essence, you're playing detective to try to find the offending line of code.

The fix for this is to rename the title property in the UIViewController. This is due to the fact that UIViewController already defines an NSString * property with a name of title.

This can often mean you're trying to assign an object to a method that can't handle it, rather than a property of that object. For example, trying to set a UILabel to an object rather than a string property on that object.
My guess is it's this line: [gemeente setText:[event gemeente]];
There could also be an issue here:
#property (nonatomic) Event *event;
You haven't set Event *event as an instance variable but are referencing it as one. Try self.event for accessing event as you have it above.

Related

arc with navigation delegate error property delegate not found on object of type viewcontroller

I'm hoping someone can shed some light on my question below.
I'm getting a property delegate not found on object of type viewcontroller error on when I declare the delegate in the parent view:
Here's the relevant code in the parent .h file:
#protocol ModalViewDelegate
- (void)didReceiveFrequencyMessage:(NSString *)message;
#end
#interface jhsManageRemindersViewController : UIViewController<UIAlertViewDelegate, UINavigationControllerDelegate, ModalViewDelegate>
and here's where I call the child view:
jhsScheduleViewController *jhsScheduleController = [[jhsScheduleViewController alloc]
initWithNibName:#"jhsScheduleViewControllerr" bundle:nil];
jhsScheduleController.delegate = self;
// Create the navigation controller and present it modally.
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:jhsScheduleController];
navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:navigationController animated:YES];
and here's part of my child .h file
#protocol ModalViewDelegate ;
#interface jhsScheduleViewController : UIViewController {
//id<ModalViewDelegate> delegate;
// __unsafe_unretained id <ModalViewDelegate> _delegate;
__weak id <ModalViewDelegate> delegate;
NSMutableString *message;
}
#property ( weak) id<ModalViewDelegate> delegate;
//#property (nonatomic, weak) id<ModalViewDelegate> delegate;
#property (nonatomic, retain) NSMutableString *message;
and finally, here's my .m usage
#synthesize delegate;
//#synthesize delegate = _delegate;
I've viewed and tried various solutions based upon Stackoverflow questions and this recommended blogpost. I've included some of my attempted solutions in commented out code, just as an FYI.
I started with the code I had in an iOS4 app but that generates the error. As a footnote, this is an app with a TabBarController and a NavigationController
Can someone tell me how to fix this so the delegate error can be resolved?
Thank you for your help!
Well, I'm not sure what the problem was. But as a last resort, I saved every file, then tried to build it, with Xcode still reporting the error, which worked.
Actually, there was an error in the initWithNibName but it ran fine until it got to that point, and correcting the typo fixed that. Again, I'm not sure what the problem was but I seem to be on my way.

No known instance method for selector error in NSMutableArray

I have a problem accessing a object in my array. I store "Place" objects in my NSMutableArray. I want to access this array for my TableView. I get the "No known instance method for selector" error in line one. See lines below.
cell.imageView = [[self.currentPlaces objectAtIndex:indexPath.row]picture];
cell.subtitleLB.text = [[self.currentPlaces objectAtIndex:indexPath.row]description];
cell.objectNameLB.text = [[self.currentPlaces objectAtIndex:indexPath.row]name];
This is my Place object:
#interface Place : NSObject{
CLLocation *objectLocation;
UIImageView *picture;
NSString *name;
NSString *description;
}
The access of the properties "description" and "name" is no problem. I just dont know why this error occurs.
Thx. Dominik
I had the same problem; what worked for me was passing the UIImage instead of the UIImageView. So your code should look like this:
#interface Place : NSObject{
CLLocation *objectLocation;
UIImage *picture;
NSString *name;
NSString *description;
}
and this
cell.imageView.image = [[self.currentPlaces objectAtIndex:indexPath.row]picture];
cell.subtitleLB.text = [[self.currentPlaces objectAtIndex:indexPath.row]description];
cell.objectNameLB.text = [[self.currentPlaces objectAtIndex:indexPath.row]name];
If that doesn't work I'll post some more code for you to look at.
You haven't actually declared any methods. What you have declared are instance variables. You should probably be using #propertys instead.
#interface Place : NSObject
#property (nonatomic, retain) CLLocation *objectLocation;
#property (nonatomic, retain) UIImageView *picture;
#property (nonatomic, copy) NSString *name;
#property (nonatomic, copy, getter=objectDescription) NSString *description;
#end
This will actually create the methods that you want. Note that I changed the method for the description property to read -objectDescription. This is because NSObject already declares the -description method and you shouldn't be overriding it with an unrelated property.
If you're on recent Clang, then this is all you need, and instance variables will get synthesized automatically (using an underbar prefix, e.g. _picture). If you're on an older version (e.g. if this causes errors), you need to add #synthesize lines, as in
#implementation Place
#synthesize objectLocation=_objectLocation;
#synthesize picture=_picture;
#synthesize name=_name;
#synthesize description=_description;
#end

Can't pass UITableViewCell didSelectRowAtIndexPath data to another view controller

I have currently got a UITableView in my main view controller. I want the data of the selected row to be passed to another view controller in my project.
Here's what I have got so far, although there is an error. Why is this? I have referenced the class and the header file in my .h file.
I would really appreciate some help with this as I've tried everything I can think of.
Simply synthesize the object in the destination view.
It will work fine...
like:
in .h
#property(nonatomic, retain) UILabel *note;
in .m
#synthesize note;
Very Simple,I think note is a UILabel,
according to You error
please use this code in AddNote. h file
NSString *noteStr; //Ios 4
IBoutlet UILabel *note;
#property(nonatomic, retain) NSString *noteStr; //Ios 4
#property(nonatomic, retain) UILabel *note;
#property(nonatomic, strong) NSString *noteStr;
#property(nonatomic, strong) UILabel *note; //Ios 5
In AddNote. .m file
#synthesize note,noteStr;
self.note.text=noteStr; //in ViewWillAppear
Some Time Application is crash Because Memory IF you Work In Ios 4 Please Correct this code
an.noteStr - [selectNote retain];
Declare static variable for global use.
Using keyword extern
Create Common.h
extern NSMutableArray *gMyBasketCollectionList;
common.m
NSMutableArray *gMyBasketCollectionList;
Use This Mutable Aarray to Store Your Data and Display in Any other
include common.h in First View And SecondView
Add Object to mutable Array in First View And
Show SecondView And Display access that Array

Adding Record using Core Data with Tab Bar Controller

I am trying to add a record to the database using core data. The appDelegate has the managed object model, context, and store coordinator setup in it. When the app is launched and I query the fetchResultsController method in one of my views the database is created matching the scheme with the correct table names and columns in it. However the problem comes when I try to add a record to the table.
The BurpListNavController.h file has the following contents (I am just learning):
#import <UIKit/UIKit.h>
#class BurpRecordController;
#interface BurpListNavController : UINavigationController <NSFetchedResultsControllerDelegate> {
BurpRecordController *burpRecordController;
NSFetchedResultsController *fetchedResultsController;
NSManagedObjectContext *managedObjectContext;
}
#property (nonatomic, retain) IBOutlet BurpRecordController *burpRecordController;
#property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
#property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
- (void)saveBurpLocal:(id)sender;
#end
I then have a view that records the burp, yes another one of the thousands of burp applications. haha. The following code is as follows:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudioTypes.h>
#class BurpLocal;
#class BurpListNavController;
#interface BurpRecordController : UIViewController <AVAudioRecorderDelegate, UIActionSheetDelegate> {
/*** Outlets to talk to the view ***/
IBOutlet UITextField *burpName;
IBOutlet UIButton *_recordButton;
/*** Standard Variables ***/
NSURL *recordedTmpFile;
//AVAudioRecorder *recorder;
NSError *error;
BurpLocal *burpLocal;
BurpListNavController *burpListNavController;
}
/*** Properties ***/
#property (nonatomic, retain) IBOutlet UITextField *burpName;
#property (nonatomic, retain) IBOutlet UIButton *recordButton;
#property (nonatomic, assign) IBOutlet BurpListNavController *burpListNavController;
#property(nonatomic, retain) BurpLocal *burpLocal;
/*** Method ***/
-(IBAction)saveRecording:(id)sender;
-(void)applicationWillTerminate:(NSNotification *)notification;
#end
When the end-user pushes the "save" button it calls the "saveRecording" method which I can step into and is great. Then I try to call the following line of code within the "saveRecording" method: [burpListNavController saveBurpLocal:sender]; thinking this will call the "saveBurpLocal" method in the nav controller and it just steps over it, does not stop at the break point in the nav controller method and then just goes to the end of the current "saveRecording" function. Does not write a record to the database or anything.
Please help! This is driving me crazy.
It's difficult to tell without more code; but it sounds like burpListNavController has not been set. When you step through the saveRecording: method, is the value of burpListNavController 0x0? If it is then you have forgotten to set that iVar somewhere.
If you have come from another language this might sound a little strange, as usually calling a method on a null pointer you cause you to crash. This isn't the case in Objective-C though, it is perfectly legal to send a message to nil; but don't expect anything to actually happen.

Pushing a UIViewController doesn't work with connections

Alright, in my rootViewController, I am able to push another viewController that I defined myself onto the screen. However, when I make any connections between that viewController and its own .h file, the program just hangs and crashes, giving me this error:
2010-06-04 15:36:13.944 pooldocfinal[11971:20b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key label1.'
That happens when i don't connect anything besides that one UILabel. Here is the code I use to declare/push the view (named balanceViewController):
- (IBAction) pushedBalanceButton
{
balanceViewController *controller = [[balanceViewController alloc] initWithNibName:#"balanceViewController" bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}
And here is the .h file of the view that I am pushing, it has only one thing in it:
#import <UIKit/UIKit.h>
#interface balanceViewController : UIViewController {
IBOutlet UILabel *label1;
}
#end
And like I said, everything works unless I actually make a connection in Interface Builder between anything in balanceViewController.xib and balanceViewController.h (in this case, it is the one UILabel object).
You should alloc a balanceViewController, not a UIViewController.
I believe if you have an IBOutlet, you need to define getters/setters. That's what Key Value coding compliant means. You can do this via #property statements and #synthesize statements, or manually if you so choose.
#interface balanceViewController : UIViewController {
IBOutlet UILabel *label1;
}
#property (nonatomic, retain) IBOutlet UILabel *label1;
#end
Then add
#synthesize label1;
to your implementation
EDIT - PS, don't forget to [label1 release] in your dealloc method