I have a tableview loaded withe records, see the code below:
- (void)viewDidLoad
{
self.navigationItem.title=#"Accounts";
// NSString *accountFile = [[NSBundle mainBundle] pathForResource:#"Accounts2" ofType:#"plist"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [paths objectAtIndex:0];
NSString *plistPath = [documentPath stringByAppendingPathComponent:#"Accounts2.plist"];
accounts = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
NSLog(#"Accounts contains : %#", accounts);
account = [accounts objectForKey:#"Account"];
NSLog(#"account %#", account);
number = [accounts objectForKey:#"Number"];
dueDay = [accounts objectForKey:#"DayDue"];
minAmount = [accounts objectForKey:#"MinAmount"];
balance = [accounts objectForKey:#"Balance"];
NSLog(#"data loaded");
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)insertNewObject:(id)sender
{
// if (!_objects) {
// _objects = [[NSMutableArray alloc] init];
// }
// [_objects insertObject:[NSDate date] atIndex:0];
// NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
// [self.tableView insertRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
if (!self.addView) {
self.addView = [[AddView alloc] initWithNibName:#"AddView" bundle:nil];
}
[self.navigationController pushViewController:self.addView animated:YES];
NSLog(#"I am done, now what");
}
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(#"Number of records is %d", [account count]);
return [account count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
NSDate *object = _objects[indexPath.row];
cell.textLabel.text = [object description];
NSString *nameOfAccount = [account objectAtIndex:indexPath.row];
cell.textLabel.text = nameOfAccount;
NSString *accountNumber = [number objectAtIndex:indexPath.row];
cell.detailTextLabel.text = accountNumber;
NSLog(#"Index %d", indexPath.row);
return cell;
}
I want to add a record to table, so I use the "InsertNewObject" method ... new screen appears, I am able to add the record to my plist, and then I execute the following line in the DetailView to return:
[self.navigationController popToRootViewControllerAnimated:NO];
Now, I want to reload my TableView with my new record:
I thought I just had to have the following viewWillAppear method like below:
- (void) viewWillAppear {
NSLog(#"View will appear");
[super viewWillAppear:YES];
[self.tableView reloadData];
}
but, my NSLog is never executed, therefore my program is never getting here... am I doing something incorrectly, thank you for any response
I have added the following two methods:
- (void) navigationController:(UINavigationController *) navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
[self.tableView reloadData];
}
-(void) navigationController:(UINavigationController *) navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
[self.tableView reloadData];
}
and changed the line
[self.navigationController popToRootViewControllerAnimated:YES];
still not working, is something still wrong.
You are not using the correct method. You are leaving out the animated argument, try using -(void)viewWillAppear:(BOOL)animated:
See UIViewController - viewWillAppear:
- (void)viewWillAppear:(BOOL)animated {
NSLog(#"View will appear");
[self.tableView reloadData];
[super viewWillAppear:animated];
}
if you are using a nav controller I belive the correct way to reload a view would be to call somethihng like this
-(void) viewWillAppear: (BOOL) animated
{
[self.tableView reloadData];
}
You could also create your own custom reloadData method that sets what you want changed and then call that method.
As pointed out, viewWillAppear takes an animated argument. However, even when you add that, popping a view controller off the navigation stack does not trigger a call to viewWillAppear:. You need to use UINavigationControllerDelegate's navigationController:willShowViewController:animated: and navigationController:didShowViewController:animated: methods to reload your table view.
Related
Am having protocol errors in AllListsViewController.m, but can't figure out why. Also have some other errors which I have commented out.
AllListsViewController.m
#import "AllListsViewController.h"
#import "ChecklistViewController.h"
#import "Checklist.h"
#import "ChecklistItem.h"
#interface AllListsViewController ()
#end
#implementation AllListsViewController
/* Method 'listDetailViewController:didFinishAddingChecklist' in protocol not implemented
Method 'listDetailViewController:didFinishEditingChecklist' in protocol not implemented
Method 'listDetailViewControllerDidCancel:' in protocol not implemented
*/
{
NSMutableArray *_lists;
}
-(NSString *)documentsDirectory
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths firstObject];
return documentsDirectory;
}
-(NSString *)dataFilePath
{
return [[self documentsDirectory] stringByAppendingPathComponent:#"Checklists.plist"];
}
-(void)saveChecklistItems
{
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:_lists forKey:#"Checklists"];
[archiver finishEncoding];
[data writeToFile:[self dataFilePath] atomically:YES];
}
-(void)loadChecklists
{
NSString *path = [self dataFilePath];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
NSData *data = [[NSData alloc] initWithContentsOfFile:path];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
_lists = [unarchiver decodeObjectForKey:#"Checklists"];
[unarchiver finishDecoding];
} else {
_lists = [[NSMutableArray alloc] initWithCapacity:20];
}
}
-(id)initWithCoder:(NSCoder *)aDecoder
{
if ((self = [super initWithCoder:aDecoder])) {
_lists = [[NSMutableArray alloc] initWithCapacity:20];
Checklist *list;
list = [[Checklist alloc] init];
list.name = #"Birthdays";
[_lists addObject:list];
list = [[Checklist alloc] init];
list.name = #"Groceries";
[_lists addObject:list];
list = [[Checklist alloc] init];
list.name = #"Cool Apps";
[_lists addObject:list];
list = [[Checklist alloc] init];
list.name = #"To Do";
[_lists addObject:list];
for (Checklist *list in _lists) {
ChecklistItem *item = [[ChecklistItem alloc] init];
item.text = [NSString stringWithFormat:#"Item for %#", list.name];
[list.items addObject:item];
[self loadChecklists];
}
return self;
}
- (void)viewDidLoad // Use of undeclared identifier 'viewDidLoad'
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [_lists count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
Checklist *checklist = _lists[indexPath.row];
cell.textLabel.text = checklist.name;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Checklist *checklist = _lists[indexPath.row];
[self performSegueWithIdentifier:#"ShowChecklist" sender:checklist];
}
#pragma mark - Table View Delegate Protocol
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
[_lists removeObjectAtIndex:indexPath.row];
NSArray *indexPaths = #[indexPath];
[tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
}
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"ShowChecklist"]) {
ChecklistViewController *controller = segue.destinationViewController;
controller.checklist = sender;
}
else if ([segue.identifier isEqualToString:#"AddChecklist"]) {
UINavigationController *navigationController = segue.destinationViewController;
ListDetailViewController *controller = (ListDetailViewController *)navigationController.topViewController;
controller.delegate = self;
controller.checklistToEdit = nil;
}
}
-(void)listDetailViewControllerDidCancel:(ListDetailViewController *)controller
{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)listDetailViewController:(ListDetailViewController *)controller didFinishAddingChecklist:(Checklist *)checklist
{
NSInteger newRowIndex = [_lists count];
[_lists addObject:checklist];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:newRowIndex inSection:0];
NSArray *indexPaths = #[indexPath];
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)listDetailViewController:(ListDetailViewController *)controller didFinishEditingChecklist:(Checklist *)checklist
{
NSInteger index = [_lists indexOfObject:checklist];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.textLabel.text = checklist.name;
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
UINavigationController *navigationController = [self.storyboard instantiateViewControllerWithIdentifier:#"ListNavigationController"];
ListDetailViewController *controller = (ListDetailViewController *)navigationController.topViewController;
controller.delegate = self;
Checklist *checklist = _lists[indexPath.row];
controller.checklistToEdit = checklist;
[self presentViewController:navigationController animated:YES completion:nil];
}
#end // Missing "end" | Expected "}"
AllListsViewController.h
#import <UIKit/UIKit.h>
#import "ListDetailViewController.h"
#interface AllListsViewController : UITableViewController <ListDetailViewControllerDelegate>
#end
ListDetailViewController.h
#import <UIKit/UIKit.h>
#class ListDetailViewController;
#class Checklist;
#protocol ListDetailViewControllerDelegate <NSObject>
-(void)listDetailViewControllerDidCancel:(ListDetailViewController *)controller;
-(void)listDetailViewController:(ListDetailViewController *)controller didFinishAddingChecklist:(Checklist *)checklist;
-(void)listDetailViewController:(ListDetailViewController *)controller didFinishEditingChecklist:(Checklist *)checklist;
#end
#interface ListDetailViewController : UITableViewController
#property (nonatomic, weak) IBOutlet UITextField *textField;
#property (nonatomic, weak) IBOutlet UIBarButtonItem *doneBarButton;
#property (nonatomic, weak) id <ListDetailViewControllerDelegate> delegate;
#property (nonatomic, strong) Checklist *checklistToEdit;
-(IBAction)cancel;
-(IBAction)done;
#end
Based on the fact that you are getting errors about a missing end and "expected '}', it sounds like you have mismatched curly brackets in your code. This sort of thing is really hard to spot by looking at code, but quite easy in Xcode. double-tap on each opening curly brace and Xcode will select the entire contents of the block up to the closing brace. Do that in your AllListsViewController.m file until you find the opening curly brace that does not have a corresponding closing brace.
I'm trying to create a simple create, display and edit contacts in Xcode 4.2 for iOS using AddressBook, so far I have done the create and display function. Now I need to implement edit function along with display. Now when I click on display it displays all the contacts and when I click on any name it shows info with a back button and a cancel button. I need to change the cancel button to edit and call the edit functionality. Below is the code of ViewController.m which I have done so far. Appreciate if u could give me a solution.
#import "ViewController.h"
#import <AddressBook/AddressBook.h>
enum MainMenuChoice
{
menuDisplayContacts,
menuCreateContacts
};
#implementation ViewController
#synthesize menuArray;
- (void)viewDidLoad {
[super viewDidLoad];
NSString *plistPath = [[NSBundle mainBundle] pathForResource:#"Menu" ofType:#"plist"];
NSLog(#"%#",plistPath);
self.menuArray = [NSMutableArray arrayWithContentsOfFile:plistPath];
}
- (void)viewDidUnload {
self.menuArray = nil;
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [menuArray count];
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *aCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (aCell == nil) {
// Make the rows look like buttons
aCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
aCell.textLabel.textAlignment = UITextAlignmentCenter;
}
aCell.textLabel.text = [[menuArray objectAtIndex:indexPath.section] valueForKey:#"title"];
return aCell;
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.section) {
case menuDisplayContacts:
[self showContacts];
break;
case menuCreateContacts:
[self createContacts];
break;
default:
[self showContacts];
break;
}
}
//Show list of all people in Contacts
- (void)showContacts {
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc]init];
picker.peoplePickerDelegate = self;
NSArray *displayItems = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonPhoneProperty],[NSNumber numberWithInt:kABPersonEmailProperty], [NSNumber numberWithInt:kABPersonBirthdayProperty],nil];
picker.displayedProperties = displayItems;
[self presentModalViewController:picker animated:YES];
}
// Dismisses the people picker and shows the application when users tap Cancel.
-(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {
[self dismissModalViewControllerAnimated:YES];
}
//For creating new contact when user tap create contacts
-(void)createContacts {
ABNewPersonViewController *picker = [[ABNewPersonViewController alloc]init];
picker.newPersonViewDelegate=self;
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:picker];
[self presentModalViewController:navigation animated:YES];
}
// Dismisses the new-person view controller when user tap cancel.
- (void)newPersonViewController:(ABNewPersonViewController *)newPersonViewController didCompleteWithNewPerson:(ABRecordRef)person {
[self dismissModalViewControllerAnimated:YES];
}
#end
I can get the desired result if I code like this in the tableview didselectRowAtIndexPath property, but I want to implement and integrate this code inside my displayContacts method instead of tableview here. Because this method is for initial screen for display and create contacts. Is there any other way that I could get the indexPath of the current selected names once I am inside the display contacts???
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ABPersonViewController *DVC=[[ABPersonViewController alloc]init];
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL,NULL);
NSMutableArray *allPeople = (__bridge NSMutableArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
int nPeople = ABAddressBookGetPersonCount(addressBook);
for(int i=0;i<nPeople;i++) {
ABRecordRef person = (__bridge ABRecordRef)([allPeople objectAtIndex:i]);
NSString *name = [self.contactAdd objectAtIndex:indexPath.row],*name2;
if(ABRecordCopyValue(person, kABPersonFirstNameProperty) != NULL) {
name2 = [[NSString stringWithFormat:#"%#", ABRecordCopyValue(person, kABPersonFirstNameProperty)]
stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
name2=[name2 stringByAppendingString:#" "];
name2=[name2 stringByAppendingString:[[NSString stringWithFormat:#"%#", ABRecordCopyValue(person, kABPersonLastNameProperty)]
stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]];
}
if([name isEqualToString:name2])
{
DVC.displayedPerson=person;
DVC.allowsEditing=YES;
[self.navigationController pushViewController:DVC animated:YES];
break;
}
}
}
-(BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {
[peoplePicker dismissModalViewControllerAnimated:NO];
ABPersonViewController *picker = [[ABPersonViewController alloc] init];
picker.personViewDelegate = self;
picker.displayedPerson = person;
// Allow users to edit the person’s information
picker.allowsEditing = YES;
[self.navigationController pushViewController:picker animated:YES];
return YES;
}
Got the solution with help of this function, but now stuck in adding delete function :P
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I'm newbie for xcode.I'm trying for an hour but i could not. How do i fix?
I'm trying to make a to-do list. The same code works other viewcontroller. I did copy-paste the codes to long. I made corrections then this error appeared. Thank you in advance for your help.
TodoMaster2ViewController.h
#import <UIKit/UIKit.h>
#import "TodoTask2.h"
#interface TodoMaster2ViewController : UITableViewController
- (IBAction)done2:(UIStoryboardSegue *)sender;
- (IBAction)cancel2:(UIStoryboardSegue *)sender;
- (IBAction)buttonEditClick2:(UIBarButtonItem *)sender;
- (void) tableView2: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath;
#end
TodoMaster2ViewController.m
#import "TodoMaster2ViewController.h"
#import "TodoDetailViewController.h"
#import "TodoAdd2ViewController.h"
#interface TodoMaster2ViewController () {
NSMutableArray *_objects2;
}
#end
#implementation TodoMaster2ViewController
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
/*
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
*/
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(applicationDidEnterBackground:) name:UIApplicationDidEnterBackgroundNotification object:app];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// paths[0];
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *plistPath = [documentsDirectory stringByAppendingPathComponent:#"data.plist"];
if ([fileManager fileExistsAtPath:plistPath] == YES)
{
NSMutableArray *readArray = [NSMutableArray arrayWithContentsOfFile:plistPath];
_objects2 = [[NSMutableArray alloc] init];
NSEnumerator *enumerator = [readArray objectEnumerator];
NSString *str = [[NSString alloc] init];
while ( str = [enumerator nextObject])
{
todoTask2 *tempTodo = [[todoTask2 alloc] init];
tempTodo.taskName2 = str;
str = [enumerator nextObject];
tempTodo.checked2 = str;
[_objects2 addObject:tempTodo];
}
[[self tableView] reloadData];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
- (void)insertNewObject:(id)sender
{
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
[_objects insertObject:[NSDate date] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
*/
#pragma mark - Table View
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _objects2.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
NSDate *object = _objects2[indexPath.row];
cell.textLabel.text = [object description];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[_objects2 removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSDate *object = _objects2[indexPath.row];
[[segue destinationViewController] setDetailItem:object];
}
}
#pragma mark yeni-task
- (IBAction)done:(UIStoryboardSegue *)segue;
{
if ([[segue identifier] isEqualToString:#"DoneAdd"] ||
[[segue identifier] isEqualToString:#"DoneKeyboard"]) {
TodoAdd2ViewController *addController = [segue sourceViewController];
if (![addController.textFieldTask2.text isEqualToString:#""]) {
if (!_objects2) {
_objects2 = [[NSMutableArray alloc] init];
}
todoTask2 *test = [[todoTask2 alloc] init];
test.taskName2 = addController.textFieldTask2.text;
if (addController.durum2.isOn) {
test.checked2 = #"yes";
} else {
test.checked2 = #"no";
}
[KGStatusBar showSuccessWithStatus:#"Yeni Fikir Eklendi!"];
//[_objects insertObject:[[NSMutableAttributedString alloc] initWithString:addController.textFieldTask.text] atIndex:_objects.count];
[_objects2 insertObject:test atIndex:_objects2.count];
[[self tableView] reloadData];
addController.textFieldTask2.text = #"";
}
[self dismissViewControllerAnimated:YES completion:NULL];
[self setEditing: NO animated: YES];
}
}
#pragma mark task tamamlandı
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
todoTask2 *temp = [_objects2 objectAtIndex:[indexPath row]];
if( [temp.checked2 isEqualToString:#"yes"] )
{
NSMutableAttributedString *tempString = [[NSMutableAttributedString alloc] initWithString:temp.taskName2];
[tempString addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(0, [tempString length])];
[tempString addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, [tempString length])];
cell.imageView.image = [UIImage imageNamed:#"check.png"];
[[cell textLabel] setAttributedText:tempString];
}
else
{
NSMutableAttributedString *tempString = [[NSMutableAttributedString alloc] initWithString:temp.taskName2];
cell.imageView.image = [UIImage imageNamed:#"uncheck.png"];
cell.accessoryType = UITableViewCellAccessoryNone;
[[cell textLabel] setAttributedText:tempString];
}
}
- (IBAction)cancel:(UIStoryboardSegue *)segue;
{
if([[segue identifier] isEqualToString:#"CancelAdd"]) {
TodoAdd2ViewController *addController = [segue sourceViewController];
addController.textFieldTask2.text = #"";
[self dismissViewControllerAnimated:YES completion:NULL];
}
}
- (IBAction)buttonEditClick:(UIBarButtonItem *)sender {
if (self.tableView.editing)
[[self tableView] setEditing:NO animated:YES];
else
[[self tableView] setEditing:YES animated:YES];
}
- (void) tableView:(UITableView *) tableView didSelectRowAtIndexPath:(NSIndexPath *) indexPath
{
todoTask2 *temp = [_objects2 objectAtIndex:[indexPath row]];
if( [temp.checked2 isEqual: #"yes"] )
{
temp.checked2 = #"no";
/*
[[_objects objectAtIndex:[indexPath row]] addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, [[_objects objectAtIndex:[indexPath row]] length])];
[[_objects objectAtIndex:[indexPath row]] addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleNone] range:NSMakeRange(0, [[_objects objectAtIndex:[indexPath row]] length])];
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
*/
}
else
{
temp.checked2 = #"yes";
/*
[[_objects objectAtIndex:[indexPath row]] addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, [[_objects objectAtIndex:[indexPath row]] length])];
[[_objects objectAtIndex:[indexPath row]] addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt:NSUnderlineStyleSingle] range:NSMakeRange(0, [[_objects objectAtIndex:[indexPath row]] length])];
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
*/
}
[[self tableView] reloadData];
//[_objects setObject: atIndexedSubscript:[indexPath row]]
}
- (void)applicationDidEnterBackground:(NSNotification *)notification {
NSLog(#"Entering Background");
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// paths[0];
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *plistPath = [documentsDirectory stringByAppendingPathComponent:#"data.plist"];
//NSArray *keys = [[NSArray alloc] initWithObjects:#"task", nil];
NSMutableArray *array = [[NSMutableArray alloc] init];
NSEnumerator *enumerator = [_objects2 objectEnumerator];
todoTask2 *tempTodo;
while ( tempTodo = [enumerator nextObject])
{
[array addObject:tempTodo.taskName2];
[array addObject:tempTodo.checked2];
}
[array writeToFile:plistPath atomically:YES];
}
#end
Sorry for this. This is my eror.
http://d.pr/i/s40r
Incomplete implementation usually means that you've declared some methods in your .h file, but haven't written all the implementations in your .m file. If you think that you have already written those implementations, check that the method signatures are exactly the same in both files.
Also, you declare tableView2:didSelectRowAtIndexPath:. Probably what you want here is to just declare the delegate method tableView:didSelectRowAtIndexPath: (no 2) and check which table view is sending the message within that method. It could be that method which is causing the error, as I can't see the implementation in your code (I checked quickly, so it might actually be there).
I have a UITableView thats supposed to show the contents of a folder from dropbox when it loads. I know its getting the data from dropbox by using log statements. I reload the data in the table after it gets the data from drop box but it still shows nothing. Please help
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
uploadFileButton = [[UIBarButtonItem alloc] initWithTitle:#"Upload" style:UIBarButtonItemStyleBordered target:self action:#selector(uploadFile:)];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.navigationItem.leftBarButtonItem = uploadFileButton;
self.title = #"DropBox";
[[self restClient] loadMetadata:#"/"];
}
- (void)restClient:(DBRestClient*)client loadedMetadata:(DBMetadata*)metadata {
for (DBMetadata *file in metadata.contents) {
NSLog(#"\t%#", file.filename);
[dropBoxArray addObject:file.filename];
}
NSLog(#"%#", dropBoxArray);
[self.tableView reloadData];
}
- (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];
}
cell.textLabel.text = [dropBoxArray objectAtIndex:indexPath.row];
NSLog(#"%#", cell.textLabel.text);
return cell;
}
You just need to show ProcessIndicator while you are making request
- (void)viewDidLoad
{
[super viewDidLoad];
uploadFileButton = [[UIBarButtonItem alloc] initWithTitle:#"Upload" style:UIBarButtonItemStyleBordered target:self action:#selector(uploadFile:)];
self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.navigationItem.leftBarButtonItem = uploadFileButton;
self.title = #"DropBox";
[[self restClient] loadMetadata:#"/"];
[self showProcessIndicator]; //Your code for showing ProcessIndicator
}
And Hide when u get this method called.
- (void)restClient:(DBRestClient*)client loadedMetadata:(DBMetadata*)metadata {
for (DBMetadata *file in metadata.contents) {
NSLog(#"\t%#", file.filename);
[dropBoxArray addObject:file.filename];
}
NSLog(#"%#", dropBoxArray);
[self.tableView reloadData];
[self hideProcessIndicator];
}
This will definitely solve your problem.
Have a happy Coding ;)
Never mind i got it. This was the correct call to load metadata:
[[self restClient] loadMetadata:#""];
I'm a beginning programmer. And I had a question.
I currently have a Table View in my app. There are three rows to it, History, Theory, and Applied Use. I would like each one to go to a different detail view. However, each one only clicks to one of the detail views.
I think the issue is at
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:#"Magnets_AU_Aubrey" bundle:[
Please help any. The three XIB's are Magnets_AU_Aubrey, Magnets_History_Aubrey, and Magnets_Theory_Aubrey
#import "DisclosureButtonController.h"
#import "NavAppDelegate.h"
#import "DisclosureDetailController.h"
#import "DetailViewController.h"
#implementation DisclosureButtonController
#synthesize list;
- (void)viewDidLoad {
NSArray *array = [[NSArray alloc] initWithObjects:#"History", #"Theory", #"Applied Use", nil];
self.list = array;
[array release];
[super viewDidLoad];
}
- (void)viewDidUnload {
self.list = nil;
[childController release], childController = nil;
}
- (void)dealloc {
[list release];
[childController release];
[super dealloc];
}
#pragma mark -
#pragma mark Table Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return [list count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString * DisclosureButtonCellIdentifier =
#"DisclosureButtonCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
DisclosureButtonCellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:DisclosureButtonCellIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
NSString *rowString = [list objectAtIndex:row];
cell.textLabel.text = rowString;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
[rowString release];
return cell;
}
#pragma mark -
#pragma mark Table Delegate Methods
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailViewController *dvController = [[DetailViewController alloc] initWithNibName:#"Magnets_AU_Aubrey" bundle:[
NSBundle mainBundle]];
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;
}
- (void)tableView:(UITableView *)tableView
accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
if (childController == nil) {
childController = [[DisclosureDetailController alloc] initWithNibName:#"MagnetsAubreyCreditsDisclosureDetail" bundle:nil];
}
childController.title = #"Disclosure Button Pressed";
NSUInteger row = [indexPath row];
NSString *selectedMovie = [list objectAtIndex:row];
NSString *detailMessage = [[NSString alloc]
initWithFormat:#"School",selectedMovie];
childController.message = detailMessage;
childController.title = selectedMovie;
[detailMessage release];
[self.navigationController pushViewController:childController animated:YES];
}
#end
NSArray *array = [[NSArray alloc] initWithObjects:#"History", #"Theory", #"Applied Use", nil];
Now do the same for xibs. Create array and fill it with xib names. Then in didSelectRowAtIndexPath to get correct xib name apply the same logic as you do in cellForRowAtIndexPath for getting cell text.