I would like to display popovers with UITableView's as content (this works) on some button presses and then get the selected item as string as buttontitle or some textview text. I've found a few example on how to do this with protocols but still get an error.
My code:
In popoverViewController.h
#protocol popoverViewControllerDelegate <NSObject>
-(void)getRowText:(NSString *)string;
#end
I declare an id delegate2 variable and set its property to:
#property(nonatomic,assign) id<popoverViewControllerDelegate> delegate2;
In the popoverViewController.m file I synthesize the variable, and in didSelectRowAtIndexPath method I have this, and this line seems to cause the error I`m having:
[self.delegate2 getRowText:[someArray objectAtIndex:indexPath.row];
In mainViewController.m I add the popoverViewControllerDelegate to the ViewControllers protocol and have its header file imported. And then have some code in the -(void)getRowText: method which doesnt get called.
UIPopovers and such are set up as they work as needed, problem arises when I press a row in the tableview. I get the
Terminating app due to uncaught
exception
'NSInvalidArgumentException', reason:
'* -[UIPopoverViewController
getRowText:]: unrecognized selector
sent to instance 0x57ca80'
Could anyone give some advice with this?
Finally found the error and cant believe how silly I/it was.
I had a viewController.delegate2 = self. line with period instead of a semicolon, I wonder why it compiled tho.
Related
I am using htautomcomplete to add autocompletion to a textfield and getting the error below.
As far as I know I have made the field in question an HTautomplete field but it is saying that it is trying to send the message to an UITextField. Could this be error or what else could cause this? Thanks for any ideas.
[UITextField setAutocompleteType:]: unrecognized selector sent to instance 0x17eea9a0
(lldb)
//code creating property
#property (unsafe_unretained, nonatomic) IBOutlet HTAutocompleteTextField *titleField;
Since this is an IBOutlet, it's most likely that you didn't set the class of your UITextField in the .xib file to be an HTAutocompleteTextField.
You can do so by selecting the object in your .xib file, then going to the Identity Inspector and setting the class under Custom Class.
When I run my iOS app on the iPhone 6 simulator on Xcode 6.1 it stops on this line:
[cell configure:[feeds objectAtIndex:indexPath.row]];
Error:
'-[UITableViewCell configure:]: unrecognized selector sent to instance 0x7ff971e1f920'
Presumably you've defined a custom cell subclass with a configure: method.
Your subclass isn't being used - that message means you're calling the method on a plain UITableViewCell.
The most common cause of this is forgetting to set the cell class in the storyboard. Otherwise, you'll need to show how you're creating cell.
You have called the configure method on a UITableViewCell instance, but this class doesn't have that method. I suspect that you meant to instantiate your own UITableViewCell subclass that does have that method.
I'm beginner in working with UIKit. When I tired to work with UIPickerView in iOS 7 SDK I faced to a hard-to-solve problem.
We know that UIPickerView needs two resources to work perfectly: dataSource & delegate. So I wrote a class named "KMPickerProtocols". I adopted it to UIPickerViewDataSource & UIPickerViewDelegate Protocols and then I added some extra setter methods to it.
KMPickerProtocols is adopted to all of essential methods of dataSource and delegate Protocols + the necessary optional method for setting title of each row (pickerView:titleForRow:forComponent). all these methods get things done without any problem (in normal situations).
Finally I set the delegate and dataSource properties of my UIPickerView (named _accountPicker) manually with this piece of code:
NSArray *delegateAgent = [[KMTwitterDelegate new] run ];
_accountPicker.dataSource = [delegateAgent objectAtIndex:0];
_accountPicker.delegate = [delegateAgent objectAtIndex:1] ;
(the run method is designed to set some properties including height of each row and ...)
Now, when I run my app it will show my twitterAccounts stored in system(accounts framework) in the form of UIPickerView. but there is a problem: As soon as I scroll the picker view or tap on any row, the program will crash and I get BAD_ACCESS (code=2 , address = 0x1) in this line of code:
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([KMAppDelegate class]));
}
and also there are sometimes that I get signal SIGABRT in above line. in these situations Log Says:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSMallocBlock pickerView:titleForRow:forComponent:]: unrecognized selector sent to instance 0x8c75ad0'
I will appreciate if you help me to deal with this problem. I really don't know where the bug is. but I guess this screen shots will be helpful to find that:
The problem in above screenshot is that UIPicker called the "pickerView:titleForRow:forComponent" method for row 0, three times instead of one time. I just don't know whether that is this because myFault or because the typical behaviour of UIPicker.
You are sending the message pickerView:titleForRow:forComponent: to an object of type NSMallocBlock. This is a message automatically sent from the picker to its datasource, so my assumption is that you are assigning the datasource:
_accountPicker.dataSource = [delegateAgent objectAtIndex:0];
The datasource you assign does not conform the protocol UIPickerViewDataSource
Checkout what returns [delegateAgent objectAtIndex:0]; and make sure it is what you expect it to be.
SO, I have a property to a UICollectionView Object
#property (strong, nonatomic) IBOutlet UICollectionView *collectionViewVARIABLE;
I held control and dragged the mouse, it's all linked up.
my problem is that it doesn't seem to actually work.
I try calling
[self.collectionViewVARIABLE registerClass:[MFH_mainfeed_CondensedViewCell class] forCellWithReuseIdentifier:#"MainIpadFeedCell"];
I get this error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier MainIpadFeedCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
If I put this call within cellForItemAtIndexPath using collectionView instead of the variable, it works.
I've tried the following on a button click, also nothing.
self.collectionViewVARIABLE.backgroundColor = [UIColor blackColor];
I have been at this for three days. My head hurts. Can somebody please tell me what I am missing.
I recently started playing with the awesome UICollectionView API, making reasonable progress, but have been stuck for almost all day with an issue I'm hoping someone can help me with:
I need to add some custom details to certain cells' attributes.
In order to do this, the right approach seem to be to subclass UICollectionViewLayoutAttributes and add the properties I need to my subclass. So far so good, except that when I return my LayoutAttributesSubclass, I always get the, somehow obscure, following error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: key cannot be nil'
Having tried to track this down for a while, I'm under the impression that the error is related to representedElementKind and representedElementCategory being nil in my subclass's instance. But those properties are read only, so I can't set those.
I've managed to somehow bypass the error by cheating, getting a regular UICollectionViewAttributes instance, then changing it to a LayoutAttributesSubclass using object_setClass, but this then raises a ton of other issues, plus seems rather shady to me.
In short, does anyone knows what the error above means, and how to correctly create/use UICollectionViewLayoutAttributes subclasses?
When setting up custom attributes, you need to subclass UICollectionViewLayoutAttributes and subclass UICollectionViewLayout and "declare" your custom attribute subclass class name by overriding +(Class)layoutAttributesClass in your UICollectionViewLayout class. The system calls this class method to see if there is a custom class to be supplied when you use the factory method for instantiating/dequeuing layout attribute objects.
#interface YourCustomCollectionViewAttributes : UICollectionViewLayoutAttributes
#property (nonatomic) UIEdgeInsets myCustomProperty
#end
#interface YourCustomCollectionViewLayout : UICollectionViewLayout
#end
#implementation YourCustomCollectionViewLayout
+ (Class)layoutAttributesClass
{
return [IRTableCollectionViewLayoutAttributes class];
}
#end
This is correct according to the documentation and should prevent the particular error you are having. Also when you implement custom iVars, be sure to implement an override for -(id)copyWithZone: or the UICollectionView will lose any custom values you have applied to your custom collection view object.