iOS - integrate Kal library in xcode 6 errors - iphone

I Work with xCode 6 how can i integrate Kal calendar library to my project
I follow instructions on Integrating Kal into Your Project
its fine with first steps , but i find problem in integrating to my View
here what I do :
1- I create property of kalViewController and connected to my View
#property (nonatomic, weak) IBOutlet KalViewController *kal;
kal.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"Today", #"") style:UIBarButtonItemStyleBordered target:self action:#selector(showAndSelectToday)];
kal.delegate = self;
dataSource = [[EventKitDataSource alloc] init];
kal.dataSource = dataSource;
[self.navigationController pushViewController:_calendarView animated:YES];
but i got errors i cant fix it
Undeclared selector (showAndSelectToday)
assigning to id <UItableViewdelegate > from incompatible type calendar * const _ strong
and some other error
any one can help me

i figure why this problem happen
For
Undeclared selector (showAndSelectToday) Error
the answer add to your class this method
- (void)showAndSelectToday
{
[kal showAndSelectDate:[NSDate date]];
}
For
assigning to id from incompatible type calendar * const _ strong Error
this error appear when I use kal.delegate = self;
in yourclass.h file add UITableViewDelegate
For me its Calendar.h
#interface Calendar : UIViewController< UITableViewDelegate >

Related

Popover view for iPhone using XCode 5

I wanted to reuse the popover for iPhone described in this video which is exactly what I need.
The problem is that I couldn't bind a UIViewController property to the popover's UIViewController like in the video.
One difference with the video is that it has been made using XCode 4.2 and I'm using XCode 5.
So the question is: How to make a popover for iPhone like in the video on XCode 5?
Here is the XCode 5 project I am struggling with.
I figured out a way to get popover to work on iPhone and iPad programmatically !
Create a category to make popover available on iPhone (more details here)
//UIPopover+Iphone.h
#interface UIPopoverController (overrides)
+ (BOOL)_popoversDisabled;
#end
//UIPopover+Iphone.m
#implementation UIPopoverController (overrides)
+ (BOOL)_popoversDisabled { return NO;
}
#end
Create the button which will show the popover and implement the method it calls
ExampleUIViewController.h
#interface ExampleViewController : UIViewController <UIPopoverControllerDelegate>
#property (strong, nonatomic) UIButton *detailButton;
#property (nonatomic, retain) IBOutlet UIPopoverController *poc;
UIPopoverController poc has to be held in an instance variable, more details here.
ExampleUIViewController.m
- (void)viewDidLoad {
_detailButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_detailButton addTarget:self
action:#selector(showPop:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_detailButton];
}
-(void)showPop:(UIButton *)button {
UIViewController *detailsViewController = [[DetailsViewController alloc] initWithNibName:#"DetailsViewController" bundle:nil];
self.poc = [[UIPopoverController alloc] initWithContentViewController:detailsViewController];
[self.poc setDelegate:self];
[self.poc presentPopoverFromRect:_detailButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}
Create the UIViewController that will contain what's displayed inside the popover (called DetailsViewController in the example)
Simply create it in your project by a right click -> New File -> Objective c class -> UIViewController and tick the box "With XIB".
Then a popover will appear right next to the button when tapped.
Tested OK on iOs5 and above.

Objective-c / xcode - Access button state in different class

So I tried this in many different ways but I can't get it to work. Im trying to change the state of a UIbutton in a different class.
class1.h
#property (strong, nonatomic) IBOutlet UIButton *monthly;
class2.m
- (void)viewDidLoad
{
ViewController *vc = [[ViewController alloc] init];
vc.monthly.enabled = NO;
}
Whatever I try and where ever I put the code, the button state is not changing. When I log the state in class2.m:
NSLog(vc.monthly.enabled ? #"Yes" : #"No");
It always returns No, even if I just stated it as YES in my class2.m. Long story short: My button property is not updating from a different class. Please tell me if you need to see any more code and i'll update asap.
i think problem is with class instance. the following line create new instance
ViewController *vc = [[ViewController alloc] init];
that's why your button state is not changing you have to get reference of your previously created intstace no need to create new instance.
for this you can use AppDelegate file to declare property of class1.
see following code
AppDelegate.h
#Property(nonatomic, ratain) ViewController *vc;
AppDelegate.m
#synthesize vc;
now alloc & initialize vc whenever you need it like following.
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication
sharedApplication] delegate];
appDelegate.vc=[[ViewController alloc] init];
also don't forgot to import AppDelegate.h file where you write above code.
now using appDelegate.vc you can use all property of View Controller in all classes of you project.
The main problem is you are creating new instance each time when you are going to check the button state. But the button state is for the button which you have created in class1.h. So you have need that you should create button in Appdelegate class and fetch the instance from Appdelegate in the class where you are checking the status of button and check the status of button. I think it will help.
Access the button using the object of the ViewController class that is already in the stack. No need to creat a new object like ViewController *vc = [[ViewController alloc] init];. When you are doing this it creates a new object so you are not getting the write thing.

UIRefreshControl issues

I am trying to implement the UIRefreshControl in my application. I have an xib file and I added a UITableViewController to the empty nib file and I set the refresh property to "enabled". Also I have added code to the viewDidLoad and a custom refresh method. The problem is I have an error I can't find any information on....in my viewDidLoad I get "Property 'refreshControl' not found on object of type ViewController"
- (void)viewDidLoad{
[super viewDidLoad];
self.myTableView =
[[UITableView alloc] initWithFrame:self.view.bounds
style:UITableViewStyleGrouped];
self.myTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight;
self.myTableView.delegate = self;
self.myTableView.dataSource = self;
[self.view addSubview:self.myTableView];
UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:#"Pull to Refresh"];
[refresh addTarget:self action:#selector(refreshView:) forControlEvents:UIControlEventValueChanged];
self.refreshControl = refresh;
}
-(void)refreshView:(UIRefreshControl *)refresh {
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:#"Refreshing data..."];
// custom refresh logic would be placed here...
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"MMM d, h:mm a"];
NSString *lastUpdated = [NSString stringWithFormat:#"Last updated on %#",
[formatter stringFromDate:[NSDate date]]];
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:lastUpdated];
[refresh endRefreshing];
}
I have no idea why that property isn't available....what am I missing?
Looks like I need to inherit from UITableViewController in my ViewController.h file. If I already have UITableView there how do I inherit from both? If I change my code from ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> to ViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> then I get an error:
error: NSInternalInconsistencyException',
reason: '-[UITableViewController loadView] loaded the "ViewController_iPhone" nib but didn't get a UITableView.'
You can add UIRefreshControl as a subview to your UITableView.
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:#selector(handleRefresh:) forControlEvents:UIControlEventValueChanged];
[self.myTableView addSubview:refreshControl];
As per Dave's comment, this may break in future version of iOS. So please be careful while using this and try to raise a bug report to apple regarding this.
Update:
A better approach is by adding UITableViewController as a ChildViewController of self and then adding tableViewController.tableView as the subview of self.view. You dont have to do any hack to make it work in this way.
[self addChildViewController:tableViewController];
[self.view addSubview:tableViewController.tableView];
You can define the frame for tableView accordingly. Using this approach, UIRefreshControl should work in the same way as it works for UITableViewController.
`
Things to Remember:
UIRefreshControl only for UITableViewController, so your class should be the subclass of UITableViewController.
UITableViewController has a property refreshControl, you should allocate a UIRefreshControl
and set it to that property.
Ex:
UITableViewController *tableViewController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
UIRefreshControl *refreshControl = [[UIRefreshControl alloc] init];
[refreshControl addTarget:self action:#selector(refreshControlAction:) forControlEvents:UIControlEventValueChanged];
tableViewController.refreshControl = refreshControl;
All of these are complex ways of doing something simple.
You don't need to add a refresh control, or declare one in your viewController. Adding pull-to-refresh is a two-step process.
Step 1: In your storyboard, go to your tableViewController and, where it says "Refreshing", select "Enabled".
Step 2: Add the following code to your tableViewController.m file, in viewDidLoad:
[self.refreshControl addTarget:self
action:#selector(refresh)
forControlEvents:UIControlEventValueChanged];
That's the entire process, other than doing stuff in your -refresh method. When you want it to stop refreshing, call [self.refreshControl endRefreshing];.
Your ViewController class must be a subclass of UITableViewController in order to have access to the refreshControl property.
I would recommend you to make separate UITableViewController Subclass for myTableView.
And then by using addChildviewController or iOS6 ContainerView to add that class within original ViewController. That way even in the part of View, you can use UIRefreshControl.
Accepted answer is not official way, so it could break in future release as comment said...

iPhone: IBAction Causes "Unrecognized Selector Sent to Instance" Error

I'm working on my first real iPhone app, a simple To-Do list application to help me organize stuff, except I'm getting an "unrecognized selector sent to instance 0x".
Specifically:
2010-02-20 14:30:09.200 ToDoApp[88562:20b] *** -[NSCFDictionary switchViews:]: unrecognized selector sent to instance 0x3d22de0
2010-02-20 14:30:09.201 ToDoApp[88562:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFDictionary switchViews:]: unrecognized selector sent to instance 0x3d22de0'
I've looked around and figured out that it might be a connection problem in IB, but I'm new to this whole connecting thing (man, I wish they supported Java or Python), so here's how it's laid out. I've got 3 classes, a SwitchViewController, a MainScreenViewController, and a ToDoListViewController. When I hit a button on MainScreenViewController, I trigger the "switchViews" function that's throwing this problem. They way I've got it set up is that the button (a UIBarButtonItem) has the "sentAction" go to switchViews. This ViewButton has its reference outlet as a IBOutlet in SwitchViewController.
So here's the .h for SVC:
#import <UIKit/UIKit.h>
#class MainScreenViewController;
#class ToDoListViewController;
#class EditViewController;
#define kMinimumGestureLength 25
#define kMaximumVariance 5
#interface SwitchViewController : UIViewController {
MainScreenViewController *mainScreenViewController;
ToDoListViewController *toDoListViewController;
EditViewController *editViewController;
IBOutlet UIBarButtonItem *viewButton;
CGPoint gestureStartPoint;
}
#property (retain, nonatomic) MainScreenViewController *mainScreenViewController;
#property (retain, nonatomic) ToDoListViewController *toDoListViewController;
#property (retain, nonatomic) EditViewController *editViewController;
#property (retain, nonatomic) IBOutlet UIBarButtonItem *viewButton;
#property CGPoint gestureStartPoint;
-(IBAction)switchViews:(id)sender;
And for the switchViews function:
-(IBAction) switchViews:(id)sender
{
NSLog(#"Switching views");
if(self.toDoListViewController.view.superview == nil){
if(self.toDoListViewController ==nil){
ToDoListViewController *toDoVC = [[ToDoListViewController alloc] initWithNibName:#"ToDoListView" bundle:nil];
self.toDoListViewController = toDoVC;
//[toDoVC release];
}
[mainScreenViewController.view removeFromSuperview];
[self.view insertSubview:toDoListViewController.view atIndex:0];
}
else{
if(self.mainScreenViewController == nil){
MainScreenViewController *mainController = [[MainScreenViewController alloc] initWithNibName:#"MainScreenView" bundle:nil];
self.mainScreenViewController = mainController;
//[mainController release];
}
[toDoListViewController.view removeFromSuperview];
[self.view insertSubview:mainScreenViewController.view atIndex:0];
}
}
So in short, I'm totally lost, and this is really frustrating. Anyone have any advice, or need any more code?
We just ran into the same problem. It seems we released the ViewController object in the AppDelegate and then our nib view tried to invoke an IBAction (on the view controller). Half the time we were getting "EXC_BAD_ACCESS" (aka messaging a released object), and half the time we were getting "unrecognized selector sent to instance" of NSCFString, NSCFArray, all sorts of things (aka messaging an area of memory now taken up by a different object).
Just check your ViewController hasn't been released.
Okay, got the solution pointed out to me. Should have had it routed through FirstResponder (I ... really don't understand why that works, but at this point I'm just happy it works.)
I'm not sure how first responder works anyways (none of the books I have really mention it), but it... works? If someone wants to give me a rundown, that'd be useful... but this question has been answered.
I'm going to guess the problem is in your nib file.
The error means that upon clicking the button, the button tries to send a message/method-call of switchView to an NSDictionary object which of course has no such method. The error then lays in where the buttons action is pointed.
Check the nib for this view. Look at the File Owner and check the class assigned to it. Make sure it is SwitchViewController and not a dictionary for some reason. If the File Owner property is set to a dictionary class it will load a dictionary and try to send the action method it to it.
The right answer is this:
The view controller that we assign as the first screen in the app delegate shouldn't be released in the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method. In your case the first screen is MainScreenViewController.
It (MainScreenViewController instance)should be released in app delegate's dealloc method.
- (void)dealloc
{
[_window release];
[mainScreenViewController release];
[super dealloc];
}
This might also help. The Analyzer routine recommended I release a few objects, and I did. Turns out, I needed those objects in the app. In the xAppDelegate.m file (or whatever) in the appDidFinishLaunching method/message/function/routine/thing, use
UINavigationController *navController = [[UINavigationController alloc] init];
instead of
UINavigationController *navController = [[[UINavigationController alloc] init] autorelease];
Also, Analyzer recommended I release the object I pushed onto the nav controller. Big mistake. That file was my menu screen and when I pressed a button, I received a unrecognized selector sent to instance. Apparently, it was calling IBAction on NSString and NSDictionary, which is not good.
FYI I was getting this when using ARC and the xib was being loading and put onto the screen, but somehow the VC itself was not being retained.
I solved it by adding a variable to store reference in the VC that was presenting it.
The problem is, you have initiated the UIViewController instance as a method variable. So the view controller have no scope after the execution of the method and so it is released from the memory cycle. So you have to make your view controller instance as class level.
#interface SwitchViewController () {
ToDoListViewController *toDoVC;
MainScreenViewController *mainController;
}
-(IBAction) switchViews:(id)sender
{
if (!toDoVC)
toDoVC = [[ToDoListViewController alloc] initWithNibName:#"ToDoListView" bundle:nil];
if (!mainController)
mainController = [[MainScreenViewController alloc] initWithNibName:#"MainScreenView" bundle:nil];
//Your stuff with the view controllers...
}

How to fix: unrecognized selector sent to instance

I am having a problem that may be simple to fix, but not simple for me to debug. I simple have a button inside a view in IB; the file's owner is set to the view controller class I am using and when making the connections, everything seems fine, ie. the connector is finding the method I am trying to call etc.
however, I am receiving this error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIApplication getStarted:]: unrecognized selector sent to instance 0x3d19130'
My code is as follows:
RootViewController.h
#interface RootViewController : UIViewController {
IBOutlet UIButton* getStartedButton;
}
#property (nonatomic, retain) UIButton* getStartedButton;
- (IBAction) getStarted: (id)sender;
#end
RootViewController.m
#import "RootViewController.h"
#import "SimpleDrillDownAppDelegate.h"
#implementation RootViewController
#synthesize getStartedButton;
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction) getStarted: (id)sender {
NSLog(#"Button Tapped!");
//[self.view removeFromSuperview];
}
- (void)dealloc {
[getStartedButton release];
[super dealloc];
}
#end
Seems simple enough...any thoughs?
It looks like you have released the RootViewController after add it to your window.
Post here the piece of code where you add RootViewController to your window.
BTW, try to comment the line where you do the release. So, instead of use:
RootViewController *viewController = [[RootViewController alloc] init];
[window addSubview:viewController.view];
[viewController release];
Do it:
RootViewController *viewController = [[RootViewController alloc] init];
[window addSubview:viewController.view];
//[viewController release];
Your method "getStarted" should work after that.
Cheers,
VFN
You're sending getStarted to UIApplication and not RootViewController. Double check to make sure the button is hooked up properly to the view controller in Interface Builder. Your code looks fine.
I have the same problem, and finally found the answer at this forum post:
http://iphonedevbook.com/forum/viewtopic.php?f=25&t=706&start=0
When you instantiate your view controller class to be pushed into the navigation controller or similar, you have to make sure you instantiate it with your custom class name, and not UIViewController. This is easy to miss, and difficult to debug.
For example:
// this is wrong
RootViewController *viewController = [[UIViewController alloc] initWithNibName:#"TestView" bundle:nil];
// It should be
RootViewController *viewController = [[RootViewController alloc] initWithNibName:#"TestView" bundle:nil];
Hope it helps!
PS: Oops. Just noticed that your error says UIApplication, and not UIViewController, unlike mine. So probably like what Marc W said, somewhere you have used UIApplication where you should have used your custom class. It is probably something like my mistake.