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
Related
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
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.
I have a tableview that will load a new .xib when pressed. The issue is, I need to pass a custom object over to the new .xib. So far, I have:
-(UITableViewCell *)doTestCellForTableView:(UITableView *)tableView atIndexPath:(NSIndexPath *)indexPath {
//some other code for current view
TestObj *testobj = [[TestObj alloc]init];
if(shouldGo){
cell.userInteractionEnabled = YES;
UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(loadTestView:)];
tapped.numberOfTapsRequired = 1;
[cell addGestureRecognizer:tapped];
}
And in that method:
-(void)loadTestView:(TestObj *)withTestObj{
TestViewController *newView =
[[TestViewController alloc] init];
//Set the property of type TestObj
newView.testobjprop = withTestObj;
[self presentViewController:newView animated:YES completion:nil];
}
It throws NSInvalidArgumentException. How can I make it to where the selector will send "testobj" that was initialized in the tableview method so I can access it there?
The new .xib loads in just fine if I comment out "newView.testobjprop = withTestObj;" in the loadTestView method. So I assume the issue lies there, and it is a matter of how to pass an object from one .xib to another.
The argument from -(void)loadTestView:(TestObj *)withTestObj is UIGestureRecognizer type so that's why you get NSInvalidArgumentException.
If you change it to -(void)loadTestView:(UITapGestureRecognizer *)withTestObj it will be the normal behavior.
That's why you need to use didSelectRow:AtIndexPath so you can pass the correct value to the viewcontroller.
Here you aren't using TestObj *testobj = [[TestObj alloc]init]; at all.
In the iOS application, I need to pass an object from one view controller to another and then switch to the new view controller. The goal is to simply relay the information. However, the object becomes NULL and is devoid of any information when the next view showed up. what? could be the reason?
Below is part of my code.
#pragma mark - Table view delegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
BIDCourse *course = self.courses[indexPath.row];
NSString *sub = course.subject;
BIDSubjectMainTwoViewController *subjectController=[[BIDSubjectMainTwoViewController alloc] init];
subjectController.title = sub;
subjectController.course=course;
[self.navigationController pushViewController:subjectController animated:YES];
}
BIDCourse *course is my custom subclass to NSObject, which has some NSStrings, and it's not nil, but when I pass it onto the next view controller, it becomes NULL.
I have met a problem like you , when I pass a object to another viewController , it has been released.
I think this is a defect of ARC , ARC think your subjectController may be no use , so it release the subjectController. Make your subjectController as a property , so ARC will not release when you pass it to another viewController.
such as :
#pragma mark - Table view delegate
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
BIDCourse *course = self.courses[indexPath.row];
NSString *sub = course.subject;
_subjectController=[[BIDSubjectMainTwoViewController alloc] init];
_subjectController.title = sub;
_subjectController.course=course;
[self.navigationController pushViewController:_subjectController animated:YES];
}
Could the problem lie in BIDSubjectMainTwoViewController.m?
subjectController.title = sub;
subjectController.course = course;
in your BIDSubjectMainTwoViewController.m file, did you #synthesize your properties?
#synthesize title = _title;
#synthesize course = _course;
You could also pass the variables along with an init function ala:
BIDSubjectMainTwoViewController.h
- (id)initWithTitle:(NSString *)title
andCourse:(BIDCourse *)course;
BIDSubjectMainTwoViewController.m
- (id)initWithTitle:(NSString *)title
andCourse:(BIDCourse *)course
{
self = [super init];
if (self) {
// Custom initialization
_title=title;
_course = course;
}
return self;
}
I encountered this similar behavior. My solution was to make a copy of the object. For your case:
BIDCourse *course = [self.courses[indexPath.row] copy];
And make sure you implement copyWithZone in the BIDCourse .m fike.
-(id)copyWithZone:(NSZone*) zone
Try this:
BIDSubjectMainTwoViewController.h
NSString *strTemp;
#property(nonatomic,retain) NSString *strTemp;
-(void) setValuestrTemp : (NSString *) str;
.m file
#synthesize strTemp;
// Write setter method
-(void) setValuestrTemp : (NSString *) str {
self.strTemp = str;
}
and use strTemp in viewWillAppear.
//Now use it
BIDSubjectMainTwoViewController *subjectController=[[BIDSubjectMainTwoViewController alloc] init];
[subjectController setValuestrTemp:sub];
[self.navigationController pushViewController:_subjectController animated:YES];
Use
NSString *sub = [course.subject copy];
subjectController.course=[course copy];
implement delegate in BIDCourse
-(id)copyWithZone:(NSZone*) zone
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