My app has local notifications . It works perfectly fine . I use the Table view controller so show the active notification . The problem i am facing is that in the table view cell , it doesn't show that if the notification is set to repeat or when it will repeat (i.e., every hour , every day etc) .
The code for the table cell that show the details about every notifications is below :
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"TableCell";
TableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Get list of local notifications
localNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *localNotification = [localNotifications objectAtIndex:indexPath.row];
NSString *dateString = [NSDateFormatter localizedStringFromDate:localNotification.fireDate
dateStyle:NSDateFormatterMediumStyle
timeStyle:NSDateFormatterNoStyle];
NSString *timeString = [NSDateFormatter localizedStringFromDate:localNotification.fireDate
dateStyle:NSDateFormatterNoStyle
timeStyle:NSDateFormatterShortStyle];
cell.TitleLabel.text = localNotification.alertBody;
cell.DateLabel.text = dateString;
cell.TimeLabel.text = timeString;
cell.repeatStatus.text =localNotification.repeatInterval;
cell.textLabel.numberOfLines = 0;
return cell;
}
i tried a lot of things , but nothing is working out . Please help .
Thanks in advance.
Related
i want to add 2 or more diffrent Custom cells in one Tableview, by using storyboard.
i know how to add diffrent cells without storyboard. I always do this by this way:
static NSString *CellIdentifier = #"Cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//pictureCell = [[DetailPictureCell alloc]init];//(DetailPictureCell *)[tableView dequeueReusableCellWithIdentifier: CellIdentifier];
pictureCell.header = true;
[pictureCell setHeader];
if (cell == nil) {
if ([indexPath row] == 0) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"HeaderAngebotViewCell" owner:self options:nil];
NSLog(#"New Header Cell");
}
if([indexPath row] ==1){
NSArray *nib = [[NSBundle mainBundle]loadNibNamed:#"productCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
And now my question: How i can do this with storyboard?
To add one custom cell is possible. But i can not add two diffrent cell. Can you help me please?
In the attributes inspector for the table view, select "Dynamic Prototypes" and below that select the number of prototype cells. Give each cell a different identifier and when dequeuing cells in cellForRowAtIndexPath, use the appropriate identifier based on indexPath.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier;
if (indexPath.row == 0) {
identifier = #"OneCellId";
} else if (indexPath.row == 1) {
identifier = #"OtherCellId";
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
//configure cell...
}
I've spent some time writing an xcode application today. I'm using a UITableView with a seperate xib for the table view cell. All is working well besides one quirky thing. In my code I set my image on the table cell xib from an array. When i run the app I've found out that the image does not appear on the table cell until I click on the table cell. And when I click on a different cell, the image on my previously selected cell disappears.
Funny thing is that I set my label on the table cell xib exactly the same way however I don't get the issue with the label.
Here is my code. I would greatly appreciate some help.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = nil;
cell = [tbHealthCheck dequeueReusableCellWithIdentifier:#"CONTENT"]; //all the cells in this table are named content (identifier for all cells in table)
if (cell == nil){
[[NSBundle mainBundle] loadNibNamed:#"FirstViewTableCell" owner:self options:nil];
cell = tcHealthCheck;
tcHealthCheck = nil;
}
UILabel *l1 = (UILabel *) [cell viewWithTag:0];
[l1 setText:[healthCheckCategory objectAtIndex:indexPath.row]];
l1.font = [UIFont fontWithName:#"arial" size:14];
[l1 setTextColor:[UIColor blackColor]];
UIImageView *img1 = (UIImageView *) [cell viewWithTag:1];
NSString *status = [healthCheckStatus objectAtIndex:indexPath.row];
if ([status isEqualToString:#"RED"])
{
img1.image = [UIImage imageNamed:#"red-light-badge.png"];
}
else if ([status isEqualToString:#"YELLOW"])
{
img1.image = [UIImage imageNamed:#"yellow-light-badge.png"];
}
else if ([status isEqualToString:#"GREEN"])
{
img1.image = [UIImage imageNamed:#"green-light-badge.png"];
}
return cell;
}
In my tableView didSelectRowAtIndexPath I can access the cell textLabel. How do I access the section label?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
topPlacesAppDelegate *appDelegate = (topPlacesAppDelegate *) [[UIApplication sharedApplication] delegate];
appDelegate.chosenPhoto = [self.topPlaces objectAtIndex:indexPath.row];
. . .
UITableViewCell *mycell = [tableView cellForRowAtIndexPath:indexPath];
NSLog(#" indexPath.section / Row = %i / %i", indexPath.section, indexPath.row);
NSLog(#" textLabel.text = %#", mycell.textLabel.text);
NSLog(#" detailTextLabel.text = %#", mycell.detailTextLabel.text);
[self performSegueWithIdentifier:#"Show Site Table" sender:nil];
}
It sounds like you are looking for the table section header. I don't think you can read or otherwise access that data. But you can set it with the method on the UITableViewDataSource:
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
Details are described here:
Change UITableView section header/footer WHILE RUNNING the app?
I am adding user defined text in a UItableView via a modal view controller.
The table is created as a NSMutableArray. on entering data in the modal view and tapping a Done button a Invalid update: invalid number of sections. error is generated.
I must update the array when the user enters data but not sure how to do that. I have attached the relevant code. Thanks for your advice.
//Number of sections
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; }
//Number of rows
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [listOfConjProcedures count];
}
//Loading the cells
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell.
cell.textLabel.text = [listOfConjProcedures objectAtIndex:indexPath.row];
return cell;
}
//Done button Delegate for the modal view
- (void)itemDetailViewController:(ItemDetailViewController *)controller didFinishAddingItem:(ChecklistItem *)item
{
int newRowIndex = [listOfConjProcedures indexOfObject:item];
[listOfConjProcedures addObject:item];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:newRowIndex inSection:0];
NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
[self dismissViewControllerAnimated:YES completion:nil];
}
I think your problem may be here:
int newRowIndex = [listOfConjProcedures indexOfObject:item];
This wouldn't have an index unless you'd already added it to the array, but in the next line you add it to the array, so it doesn't make sense.
I think you are therefore adding a row at index path 0,NSNotFound, which will confuse the table view. Either use the count of the array as the row index, or insert your new row at the start (0,0) of the table (and at index 0 of the array).
How to change it back from activity indicator to disclosure ??
the problem is:
When i didSelectRow, i made disclosure to activity indicator because it will load some picture for the next view controller and It's worked, but i dont have any luck to change it back to disclosure after pushViewController. i already tried to reload the table from the 2ndViewController but it's crashed.
So anybody have a solution for this problem..
Thanks in advance
This is my code in didSelectRow :
-(void)threadStartAnimating:(id)data
{
[activityView startAnimating];
[self.navigationController pushViewController:bdvController animated:YES];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[cell setAccessoryView:activityView];
[NSThread detachNewThreadSelector:#selector(threadStartAnimating:) toTarget:self withObject:nil];
// Navigation logic -- create and push a new view controller
if(bdvController == nil)
bdvController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:[NSBundle mainBundle]];
AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row];
bdvController.appsRecord = appRecord;
bdvController.HeaderText.text = appRecord.appName;
bdvController.title = appRecord.artist;
[bdvController.tableView reloadData];
}
The best way is to set pointer nil to the accessoryView, example:
cell.accessoryView = nil;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
cell.selectionStyle = UITableViewCellSelectionStyleGray;
In my code these operations work fine.