How to add events to Kal calendar library for iOS? - ios

I'v integrated Kal calendar in my app. Now i'v to add events to calendar that i receive from server as JSON and show a dot where an event is present on calendar. I've looked in example code given in github sample project but did not get any clue that how to implement data source for kal calendar?
Any help would be appreciated.

Holidays example provided on gitHub is good place to start with.here is how i did that-
initialize Kal calendar in your view controller as-
kal = [[KalViewController alloc] init];
kal.title = #"Calender";
kal.view.frame = CGRectMake(0, 65, 320, kal.view.frame.size.height);
[self.view addSubview:kal.view];
kal.delegate = self;
dataSource = [[KalCalendarDataSource alloc] init];
kal.dataSource = dataSource;
[kal showAndSelectDate:[NSDate date]];
and provide delegate implementation for show detail of your event
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"event selected.... ******");
Events* event = [dataSource eventAtIndexPath:indexPath];
EventDetailViewController* vc = [[UIStoryboard storyboardWithName:#"Main" bundle:Nil] instantiateViewControllerWithIdentifier:#"eventDetail"];
[vc setEvent:event];
[self.navigationController pushViewController:vc animated:YES];
}
now implement KalCalendarDataSource as given in Holidays example(HolidaySqliteDataSource) and change Holiday with your event model. There is not too much changes just model class and variable name and you will good to go.
Hope this will help.happy coading. :P

Related

MBCalendar kit framework how to add in my project

I used MBCalendar kit framework. and successfully added in my project, but problem is that months and dates cant show simulator. only one top bar show in this weeks and year show. I attached my output snap shot please find this and show bellow. I want to successfully calendar show in UI. how it possible please help.
#import "ViewController.h"
#import "CalendarKit/CalendarKit.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
CKCalendarView *calendar = [CKCalendarView new];
[calendar setDelegate:self];
[calendar setDataSource:self];
[[self view] addSubview:calendar];
}
Follow my step:
Step 1: remove you are implement all related to MBCalendar.
Step 2: include CKDemoViewController.h & CKDemoViewController.m file in your project.
Step 3: set your view design class to CKDemoViewController.
check some file: https://github.com/BhadreshKathiriya/MBCalendar
- (IBAction)btnClick:(id)sender {
[self presentViewController:[[CKDemoViewController alloc] init] animated:YES completion:nil];
//Or
[self.navigationController pushViewController:[[CKDemoViewController alloc] init] animated:YES];
}

Access view controller without re-initializing

Essentially I'm working with 3 view controllers.
Main view which starts a download. (Webview based which passes the download).
Modal download controller. (Tab based).
Downloader (HCDownload).
In the main view my download gets passed like so:
//Fire download
[activeDL downloadURL:fileURL userInfo:nil];
[self presentViewController:vc animated:YES completion:nil];
activeDL is initialized in viewDidLoad:
activeDL = [[HCDownloadViewController alloc] init];
If I removed the presentViewController, it still downloads, which is fine. Then i tap my Downloads button, it brings up the controller which defines the tabs like so:
center = [[CenterViewController alloc] init];
activeDL = [[HCDownloadViewController alloc] init];
completedDL = [[DownloadsViewController alloc] init];
activeDL.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Active Downloads"
image:nil //[UIImage imageNamed:#"view1"]
tag:1];
completedDL.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Completed Downloads"
image:nil //[UIImage imageNamed:#"view3"]
tag:2];
[self setViewControllers:[NSArray arrayWithObjects:activeDL, completedDL, nil]];
However, it is not passing the current active download. I don't know if it's a initialization problem, or my tab issue of showing the current download.
From his github, he suggests to get the current number of downloads is to call: dlvc.numberOfDownloads which for me would be
[activeDL numberOfDownloads].
I call this in the the Downloader viewWillAppear but nothing shows.
Does anybody has any suggestions or have worked with this controller?
Any help would be appreciated.
When you call:
activeDL = [[HCDownloadViewController alloc] init];
You are creating a new download controller, which has its own internal downloads array. This library, as written, has no way to pass this information from one HCDownloadViewController object to another.
Tying downloads to VC's like this will cause problems -- I recommend you rewrite this code to split that apart.
To hack around it, try to create just one HCDownloadViewController object and pass it around.
Ok so with the last comment of the other answer, "Make activeDL a member variable instead of a local variable.", got me Googling and with some tinkering and bug fixing along the way I managed to get it all up and running perfect.
I declared it all in my AppDelegate.
AppDelegate.h
#interface SharedDownloader : HCDownloadViewController <HCDownloadViewControllerDelegate>
+ (id)downloadingView;
#end
AppDelegate.m
static HCDownloadViewController *active;
#implementation SharedDownloader
+ (id)downloadingView {
if (active == nil)
active = [[HCDownloadViewController alloc] init];
return active;
}
#end
Calling to the class for downloading in my main view controller:
-(id)init{
activeDL = [SharedDownloader downloadingView];
return self;
}
//Spot where I fire the download
if (navigationAction.navigationType == WKNavigationTypeLinkActivated) {
//More code here
[activeDL downloadURL:fileURL userInfo:nil];
}
Lastly in my tab bar controller:
-(id)init {
activeDL = [SharedDownloader downloadingView];
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
activeDL.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Active Downloads" image:nil] tag:2];
}
I believe that's all of it. In any case, thanks to Lou Franco for pointing me in the right direction.

iOS - how can i add events to kal library in Objective C?

I work in project need calendar view with events , i try many libraries but finally i decide to use kal library as its have ability to add events
Calendar.h
#import "Kal.h"
#import "NSDate+Convenience.h"
#import "EventKitDataSource.h"
#interface Calendar : UIViewController<WebService_Delegate , UITableViewDelegate >
{
KalViewController *kal;
id dataSource;
}
Calendar.m
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Caledar";
kal = [[KalViewController alloc]initWithSelectionMode:KalSelectionModeSingle];
kal.selectedDate = [NSDate dateStartOfDay:[NSDate date]];
kal.delegate = self;
kal.view.frame = CGRectMake(0, 65, kal.view.frame.size.width, kal.view.frame.size.height);
[kal showAndSelectDate:[NSDate date]];
//navController = [[UINavigationController alloc]initWithRootViewController:kal];
// [self.view addSubview:navController.view];
[self initVariable];
[self getEvents];
dataSource = [[EventKitDataSource alloc] init];
kal.dataSource = dataSource;
[self.view addSubview:kal.view];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Display a details screen for the selected event/row.
EKEventViewController *vc = [[EKEventViewController alloc] init];
vc.event = [dataSource eventAtIndexPath:indexPath];
//[vc setEvent:[events_array objectAtIndex:indexPath.row]];
vc.allowsEditing = NO;
[navController pushViewController:vc animated:YES];
}
how can i pass data to dataSource to display it
here how its look like
i need set events list to my events list , i got event duplicated , its read from my calendar
thank you
You need to implement the KalDataSource protocol in an object and set that object as the datasource of your kal object. The protocol can be found here https://github.com/klazuka/Kal/blob/master/src/KalDataSource.h
Add the KalDataSource protocol to your header file
<WebService_Delegate , UITableViewDelegate, KalDataSource>
In the init method of your Calendar object set
kal.datasource = self
Implement the KalDataSource methods in your object

Passing Data from Slide menu to UITableViewController through UINavigationViewController

How can I pass data from UINavigationController to The root UITableViewController?
I have implemented the ECSlidingViewController (https://github.com/edgecase/ECSlidingViewController). User selects one of the cells in the menu that correspond to different urls I want to display information from on my tableView that sitts on top of the UINavigationController. (u know the default combination that u get my dragging UINavigationController to ur storyboard). I am able to get the data from the sliding menu to my navigationController now I am trying to pass that same info on my tableview?
In my menu I have:
UINavigationController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"NavigationTop"];
newTopViewController = [(NavigationTopViewController*)newTopViewController initWithCinema:self.myCinema];
In UINaviationController:
- (id)initWithCinema:(Cinema *)cinema {
self = [super init];
if(self) {
_myCinema = [[Cinema alloc] init];
_myCinema = cinema;
}
return self;
}
- (void) viewDidLoad {
[super viewDidLoad];
// this log works I get the info to here.
NSLog(#"url(navigation):%#", self.myCinema.cinemaURL);
//MoviesTableViewController *moviesTableViewController = [[MoviesTableViewController alloc] initWithCinema:self.myCinema];
//UITableViewController *newTopViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"MoviesTable"];
//NavigationTopViewController *newTopViewController = [[NavigationTopViewController alloc] initWithCinema:self.myCinema];
//newTopViewController = [(MoviesTableViewController *)newTopViewController initWithCinema:self.myCinema];
//[self performSegueWithIdentifier:nil sender:self.myCinema];
[self prepareForSegue:nil sender:self.myCinema.cinemaURL];
}
In my UITableView:
- (void)setCinema:(Cinema *)cinema {
// works here too
NSLog(#"Table(setCinema):%#", cinema.cinemaURL);
self.myCinema = [[Cinema alloc] init];
if(!cinema) {
cinema.cityIndex = kAstanaIndex;
cinema.name = kKeruen;
cinema.nameForText = kKeruenText;
cinema.cinemaURL = kKeruenURL;
cinema.cinemaURLTomorrow = kKeruenURLtomorrow;
}
self.myCinema = cinema;
// works here too!!!
NSLog(#"Table(myCinema):%#", self.myCinema.cinemaURL);
}
However its gone in viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
// set delegate to self
self.tableView.delegate = self;
// set loading theater's url
// does not work here: I GET NULL !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
NSLog(#"url(moviesTable):%#", self.myCinema.cinemaURL);
_model = [[MovieModel alloc] initWithURL:self.myCinema.cinemaURL];
}
None of the methods I have tried (commented in Navigation worked...) at least for me. Please give me any suggestions. Thank you in advance.
UINavigationController does not hold any data, but rather a stack of view controllers. I'd recommend you check out frameworks such as the free Sensible TableView. The framework will automatically handle detail view generation and passing data between them. Saves me tons of development time in my projects.

Using delegate from different classes

Having some difficulty getting my delegate to "work".
It works when the ClassA pushes ClassB onto the stack via UINavigationController, but ClassB does not call the delegate method (in ClassA) when ClassB is pushed by a different ClassC.
This method from within ClassA works:
- (void)openViewController:(NSString *)title:(int)dataType:(NSArray *)currentData {
ClassB *nextController = [[ClassB alloc] initWithNibName:#"ClassBView" bundle:nil];
nextController.delegate = self;
nextController.title = title;
nextController.dataType = dataType;
nextController.currentData = currentData;
nextController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:nextController animated:YES];}
How do I get this method, from ClassC, to properly designate ClassA as the delegate for ClassB???
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ClassB *nextController = [[ClassB alloc] initWithNibName:#"ClassBView" bundle:nil];
nextController.delegate = ??????????
nextController.title = [self.tableData objectAtIndex:indexPath.row];
nextController.dataType = self.dataType;
nextController.currentData = [NSArray arrayWithArray:[self.dictionary objectForKey:[self.tableData objectAtIndex:indexPath.row]]];
nextController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:nextController animated:YES];}
Appreciate any assistance. Cheers.
I feel like knowing more about the view controller hierarchy in the app would help, but it sounds like you'll need to add a reference to ClassA in ClassC that it could pass on to ClassB. So (in ClassC) nextController.delegate = self.ClassARef

Resources