iOS- How to show alertView before code starts - iphone

I have the following code:
-(IBAction)showAlertView:(id)sender{
alertView = [[UIAlertView alloc] initWithTitle:#"Atualizando" message:#"\n"delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.center = CGPointMake(139.5, 75.5); // .5 so it doesn't blur
[alertView addSubview:spinner];
[spinner startAnimating];
[alertView show];
}
-(IBAction)getContacts:(id)sender {
[self showAlertView:(id)self];
ABAddressBookRef addressBook = ABAddressBookCreate( );
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );
I want to show the alert before the rest of the IBAction begins, but im seeing the alertView only at the end of the IBAction. What am I doing wrong?
EDIT: i have:
-(IBAction)getContacts:(id)sender {
// display the alert view
[self showAlertView:self];
// do the synchronous operation on a different queue
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
ABAddressBookRef addressBook = ABAddressBookCreate( );
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );
....
if ([contact length] == 8) {
NSString *first = (NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *last = (NSString*)ABRecordCopyValue(person, kABPersonLastNameProperty);
NSString *phone = contact;
ContactInfo *user1 = [[ContactInfo alloc] init];
user1.first = first;
user1.last = last;
user1.phone = phone;
user1.person = person;
user1.phoneIdx = j;
user1.book = addressBook;
NSLog(#"phone is %#", phone);
[secondViewController.users addObject:user1];
}
ABRecordSetValue(person, kABPersonPhoneProperty, mutablePhones, &error);
}
}
bool didSave = ABAddressBookSave(addressBook, &error);
if(!didSave){
NSLog(#"error!");
}
dispatch_async(dispatch_get_main_queue(), ^{
[self hideAlertView]; // or however you want to do it
});
UIAlertView *alertAlmost = [[UIAlertView alloc] initWithTitle:#"Quase Pronto" message:#"Os seguintes contatos não tem código de área. Porfavor, selecione os contatos que você deseja adicionar o digito 9 e pressione Ok (caso não queira adicionar em nenhum, pressione Ok) " delegate:self cancelButtonTitle:#"Ok!" otherButtonTitles:nil];
[alertAlmost show];
[self presentViewController: secondViewController animated:YES completion: NULL];
});
}
I want the alert to dismiss, and then i can call the table view. Any sugestions?

Showing a UIAlertView is done asynchronously, so if you call showAlertView: at the top of the method, it'll show the alert view and then return immediately after, then do the rest of your method.
If you want the rest of your method to happen after the alert view is dismissed, you need to add yourself as the alert view's delegate, then implement the method
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
and do the rest of your stuff in there.
Edit: Okay, I think I get your problem. You're doing some time consuming synchronous operation on the main queue and that's blocking it so that the alert view isn't displayed until later.
You should move the time consuming operation to a different queue like so:
-(IBAction)getContacts:(id)sender {
// display the alert view
[self showAlertView:self];
// do the synchronous operation on a different queue
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
ABAddressBookRef addressBook = ABAddressBookCreate( );
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );
// once this operation has finished, you can hide the alert view like so:
dispatch_async(dispatch_get_main_queue(), ^{
[self hideAlertView]; // or however you want to do it
});
});
}

You need to do the rest of the code in your "getContacts:" when your alert is dismissed. Set a delegate on your UIAlertView of "self" (the view controller showing the alert) and then do the "addressBook" stuff when the user clicks the button to dismiss the alert.
For example, implement the UIAlertViewDelegate method alertView:clickedButtonAtIndex: and do your address book stuff in there (I linked the documentation for you).

I think you're saying that you want to popup an alert, like a progress indicator, and while that alert is up, you want to start your other process. Currently, you request to have the alert shown immediately, but as the other answers have said, that call is asynchronous, and the UI thread does not manage to get the alert displayed before starting on the other work.
You could try this:
-(IBAction)getContacts:(id)sender {
[self showAlertView:(id)self];
[self performSelectorInBackground: #selector(initAddressBook) withObject: nil];
}
-(void)initAddressBook {
ABAddressBookRef addressBook = ABAddressBookCreate( );
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );
}
If there's some problem with running the address book work in the background, you might even be able to give the UI thread enough time to get the alert posted with something like this:
-(IBAction)getContacts:(id)sender {
[self showAlertView:(id)self];
[self performSelector: #selector(initAddressBook) withObject: nil afterDelay: 0.1f];
}

Related

How to fetch data from web service in background and then update the UI

What i am doing is applying push view controller to move to next view from table view's didSelectMethod. And on next view controller data is fetched for that view. So, the problem is the view switches only when the data is fetched completely, and it contains images and text both. But i have already applied the lazy loading for images but the issue is to move to next view immediately and then fetch data and update the UI and tableview. Below is code i am trying.
On next view controller's didLoad method.
[NSThread detachNewThreadSelector:#selector(setImage) toTarget:self withObject:nil];
the method setImage fetching all data images and text.
-(void)setImage
{
if([type isEqualToString:#"Organisation"])
{
self.mGetDataDict = [MyEventApi members:self.mUserIdDict];
self.mRecievedDataDict = [self.mGetDataDict valueForKey:#"members"];
}
if([type isEqualToString:#"Individual"]){
self.mGetDataDict = [MyEventApi friends:self.mUserIdDict];
self.mRecievedDataDict = [self.mGetDataDict valueForKey:#"friends"];
}
if([self.mGetDataDict valueForKey:#"friends"] == [NSNull null])
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"alert" message:#"You have not added any friend yet." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
else
{
self.mFrndNameArr = [[NSMutableArray alloc]init];
self.mFrndImgArr = [[NSMutableArray alloc]init];
self.mFirstNameArr = [[NSMutableArray alloc]init];
self.mLastNameArr = [[NSMutableArray alloc]init];
self.mFrndIdArr = [[NSMutableArray alloc]init];
self.mFrndMSinceArr = [[NSMutableArray alloc]init];
self.mFrndDescArr = [[NSMutableArray alloc]init];
self.mFrndNameArr = [self.mRecievedDataDict valueForKey:#"username"];
self.mFrndImgArr = [self.mRecievedDataDict valueForKey:#"image"];
self.mFirstNameArr = [self.mRecievedDataDict valueForKey:#"firstName"];
self.mLastNameArr = [self.mRecievedDataDict valueForKey:#"lastName"];
self.mFrndIdArr = [self.mRecievedDataDict valueForKey:#"id"];
self.mFrndMSinceArr = [self.mRecievedDataDict valueForKey:#"memberSince"];
self.mFrndDescArr = [self.mRecievedDataDict valueForKey:#"description"];
[self.mFriendsTable reloadData];
}
}
Please guide for above, is i am using correct method or there is another way to do this.
Thanks in advance.
Please use GCD :)
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
//in this scope load your data from server
dispatch_async(dispatch_get_main_queue(), ^{
//use this scope to reload UI with data received from scope above
// in your case this is NSDictionary object, this object will be able to use in this scope because this scope will catch variables from scope above
});
});
you can use GCD
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
//Fire api
dispatch_async(dispatch_get_main_queue(), ^{
//update ui
});
});
I would recommend against using the NSThread API in your context. API like GCD or NSOperation are sitting at a higher level and will provide you with the solution you are looking for:
An implementation with GCD will look like this
dispatch_queue_t backgroundQueue = dispatch_queue_create("backgroundQueue", DISPATCH_QUEUE_CONCURRENT);
dispatch_async(backgroundQueue, ^{
// update your method to remove the table refresh
[self setImage];
dispatch_async(dispatch_get_main_queue(), ^{
//Update the UI on the main thread
[self.mFriendsTable reloadData];
});

iOS - add contact into Contacts?

Heyo!
Is there a way how when a user taps a button it can add or update a contact into the actual Apple Contacts Book? Some festivals have email responses include a "name card" that the receiver can download and find in their contact book.
If doing this in iOS 9 or later, you should use the Contacts framework:
#import Contacts;
You also need to update your Info.plist, adding a NSContactsUsageDescription to explain why your app requires access to contacts.
Then, when you then want to programmatically add the contact, then you can do something like:
CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
if (status == CNAuthorizationStatusDenied || status == CNAuthorizationStatusRestricted) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:#"Access to contacts." message:#"This app requires access to contacts because ..." preferredStyle:UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction actionWithTitle:#"Go to Settings" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:#{} completionHandler:nil];
}]];
[alert addAction:[UIAlertAction actionWithTitle:#"Cancel" style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alert animated:TRUE completion:nil];
return;
}
CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (!granted) {
dispatch_async(dispatch_get_main_queue(), ^{
// user didn't grant access;
// so, again, tell user here why app needs permissions in order to do it's job;
// this is dispatched to the main queue because this request could be running on background thread
});
return;
}
// create contact
CNMutableContact *contact = [[CNMutableContact alloc] init];
contact.familyName = #"Doe";
contact.givenName = #"John";
CNLabeledValue *homePhone = [CNLabeledValue labeledValueWithLabel:CNLabelHome value:[CNPhoneNumber phoneNumberWithStringValue:#"312-555-1212"]];
contact.phoneNumbers = #[homePhone];
CNSaveRequest *request = [[CNSaveRequest alloc] init];
[request addContact:contact toContainerWithIdentifier:nil];
// save it
NSError *saveError;
if (![store executeSaveRequest:request error:&saveError]) {
NSLog(#"error = %#", saveError);
}
}];
Or, even better, if you want to add the contact using the ContactUI framework (giving the user visual confirmation of the contact and let them tailor it as they see fit), you can import both frameworks:
#import Contacts;
#import ContactsUI;
And then:
CNContactStore *store = [[CNContactStore alloc] init];
// create contact
CNMutableContact *contact = [[CNMutableContact alloc] init];
contact.familyName = #"Smith";
contact.givenName = #"Jane";
CNLabeledValue *homePhone = [CNLabeledValue labeledValueWithLabel:CNLabelHome value:[CNPhoneNumber phoneNumberWithStringValue:#"301-555-1212"]];
contact.phoneNumbers = #[homePhone];
CNContactViewController *controller = [CNContactViewController viewControllerForUnknownContact:contact];
controller.contactStore = store;
controller.delegate = self;
[self.navigationController pushViewController:controller animated:TRUE];
My original answer, using the AddressBook and AddressBookUI frameworks for iOS versions before 9, is below. But if only supporting iOS 9 and later, use the Contacts and ContactsUI frameworks as outlined above.
--
If you want to add a contact to the user's address book, you use AddressBook.Framework to create a contact, and then you use the AddressBookUI.Framework to present the user interface to allow the user to add it to their personal address book using ABUnknownPersonViewController. Thus, you can:
Add AddressBook.Framework and AddressBookUI.Framework to your list under Link Binary With Libraries;
Import the .h files:
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
Write the code to create a contact, e.g.:
// create person record
ABRecordRef person = ABPersonCreate();
// set name and other string values
ABRecordSetValue(person, kABPersonOrganizationProperty, (__bridge CFStringRef) venueName, NULL);
if (venueUrl) {
ABMutableMultiValueRef urlMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(urlMultiValue, (__bridge CFStringRef) venueUrl, kABPersonHomePageLabel, NULL);
ABRecordSetValue(person, kABPersonURLProperty, urlMultiValue, nil);
CFRelease(urlMultiValue);
}
if (venueEmail) {
ABMutableMultiValueRef emailMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(emailMultiValue, (__bridge CFStringRef) venueEmail, kABWorkLabel, NULL);
ABRecordSetValue(person, kABPersonEmailProperty, emailMultiValue, nil);
CFRelease(emailMultiValue);
}
if (venuePhone) {
ABMutableMultiValueRef phoneNumberMultiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType);
NSArray *venuePhoneNumbers = [venuePhone componentsSeparatedByString:#" or "];
for (NSString *venuePhoneNumberString in venuePhoneNumbers)
ABMultiValueAddValueAndLabel(phoneNumberMultiValue, (__bridge CFStringRef) venuePhoneNumberString, kABPersonPhoneMainLabel, NULL);
ABRecordSetValue(person, kABPersonPhoneProperty, phoneNumberMultiValue, nil);
CFRelease(phoneNumberMultiValue);
}
// add address
ABMutableMultiValueRef multiAddress = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSMutableDictionary *addressDictionary = [[NSMutableDictionary alloc] init];
if (venueAddress1) {
if (venueAddress2)
addressDictionary[(NSString *) kABPersonAddressStreetKey] = [NSString stringWithFormat:#"%#\n%#", venueAddress1, venueAddress2];
else
addressDictionary[(NSString *) kABPersonAddressStreetKey] = venueAddress1;
}
if (venueCity)
addressDictionary[(NSString *)kABPersonAddressCityKey] = venueCity;
if (venueState)
addressDictionary[(NSString *)kABPersonAddressStateKey] = venueState;
if (venueZip)
addressDictionary[(NSString *)kABPersonAddressZIPKey] = venueZip;
if (venueCountry)
addressDictionary[(NSString *)kABPersonAddressCountryKey] = venueCountry;
ABMultiValueAddValueAndLabel(multiAddress, (__bridge CFDictionaryRef) addressDictionary, kABWorkLabel, NULL);
ABRecordSetValue(person, kABPersonAddressProperty, multiAddress, NULL);
CFRelease(multiAddress);
// let's show view controller
ABUnknownPersonViewController *controller = [[ABUnknownPersonViewController alloc] init];
controller.displayedPerson = person;
controller.allowsAddingToAddressBook = YES;
// current view must have a navigation controller
[self.navigationController pushViewController:controller animated:YES];
CFRelease(person);
See the ABUnknownPersonViewController Class Reference or the Prompting the User to Create a New Person Record from Existing Data section of the Address Book Programming Guide.
To present default contact controller
Step 1:
Add ContactUi.framework into project and import
#import <Contacts/Contacts.h>
#import <ContactsUI/ContactsUI.h>
Step2:
Add this code
-(void)showAddContactController{
//Pass nil to show default contact adding screen
CNContactViewController *addContactVC = [CNContactViewController viewControllerForNewContact:nil];
addContactVC.delegate=self;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:addContactVC];
[viewController presentViewController:navController animated:NO completion:nil];
}
Step3:
For getting call back when pressing DONE or CANCEL, Add <CNContactViewControllerDelegate>and implement the delegate method.
- (void)contactViewController:(CNContactViewController *)viewController didCompleteWithContact:(nullable CNContact *)contact{
//You will get the callback here
}
#import Contacts;
-(void)addToContactList
{
CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
if (status == CNAuthorizationStatusDenied || status == CNAuthorizationStatusRestricted) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:#"This app previously was refused permissions to contacts; Please go to settings and grant permission to this app so it can add the desired contact" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:#"OK" style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alert animated:TRUE completion:nil];
return;
}
CNContactStore *store = [[CNContactStore alloc] init];
[store requestAccessForEntityType:CNEntityTypeContacts completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (!granted) {
dispatch_async(dispatch_get_main_queue(), ^{
// user didn't grant access;
// so, again, tell user here why app needs permissions in order to do it's job;
// this is dispatched to the main queue because this request could be running on background thread
});
return;
}
// create contact
CNMutableContact *contact = [[CNMutableContact alloc] init];
contact.givenName = #"Test";
contact.familyName = #"User";
CNLabeledValue *homePhone = [CNLabeledValue labeledValueWithLabel:CNLabelHome value:[CNPhoneNumber phoneNumberWithStringValue:#"91012-555-1212"]];
contact.phoneNumbers = #[homePhone];
CNSaveRequest *request = [[CNSaveRequest alloc] init];
[request addContact:contact toContainerWithIdentifier:nil];
// save it
NSError *saveError;
if (![store executeSaveRequest:request error:&saveError]) {
NSLog(#"error = %#", saveError);
}
}];
}

Identifying the Push Notification Message

In my project I want to show the events and offers through push notification, but the problem is, I'm able to show the events or offers, not both. Is there any way to identify the message of Push notification. Here's the code:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSString *message = nil;
id alert = [userInfo objectForKey:#"alert"];
if ([alert isKindOfClass:[NSString class]]) {
message = alert;
} else if ([alert isKindOfClass:[NSDictionary class]]) {
message = [alert objectForKey:#"body"];
}
if (alert) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Title"
message:#"AThe message." delegate:self
cancelButtonTitle:#"button 1"
otherButtonTitles:#"button", nil];
[alertView show];
}
NSString *contentsInfo = [userInfo objectForKey:#"contTag"];
NSLog(#"Received contents info : %#", contentsInfo);
NSString *nibName = [AppDelegate fetchNibWithViewControllerName:#"EventsViewController"];
EventsViewController *evc = [[EventsViewController alloc] initWithNibName:nibName bundle:nil];
evc.newEvent = YES;
[self.navigationController pushViewController:evc animated:YES];
[UIApplication sharedApplication].applicationIconBadgeNumber = [[[userInfo objectForKey:#"aps"] objectForKey: #"badgecount"] intValue];
}
alert is always an NSDictionary with two keys: body and show-view. The value of the former is the alert message and the latter is a Boolean (false or true). If false, the alert’s View button is not shown. The default is to show the View button which, if the user taps it, launches the application.
check the docs
To identify type of the message you can provide additional fields, as described here
Example:
{
"aps":{
"badge":1,
"alert":"This is my special message!",
"mycustomvar1":"123456",
"mycustomvar2":"some text",
"myspecialtext":"This is the best!",
"url":"http://www.mywebsite.com"
}
}

How to call a variable with a value calculated from one method in another method?

My code does a calculation upon a button press in "IBAction" and returns the result in a string as the "message" in "UIAlertView".
else{
NSString *str = [[NSString alloc] initWithFormat:#"You require an average GPA of at least %.2f to achieve your Goal of %#", gpagoal, (NSString *)[myPickerDelegate.myGoal objectAtIndex: [myPicker selectedRowInComponent:0]]];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Nothing is Impossible"
message:str
delegate:self
cancelButtonTitle:#"Good Luck"
otherButtonTitles:#"Tweet",nil];
//show alert
[alert show];
[alert release];
NSLog(#"All Valid");
}
i have a problem of how to pull the "gpagoal" value from the calculation's "IBAction" method.
below is the code for the standalone button for tweeting, which works if i am able to port over the gpagoal value from the other method.
- (IBAction)sendEasyTweet:(id)sender {
// Set up the built-in twitter composition view controller.
TWTweetComposeViewController *tweetViewController = [[TWTweetComposeViewController alloc] init];
// i have problem trying to pull the result "gpagoal" from the calculation's "IBAction" method as i dunno how to pull out variable from a method to another method.
NSString *str2 = [[NSString alloc] initWithFormat:#"I need an average GPA of at least %.2f this semester to achieve my Goal of %#", gpagoal, (NSString *)[myPickerDelegate.myGoal objectAtIndex: [myPicker selectedRowInComponent:0]]];
// Set the initial tweet text. See the framework for additional properties that can be set.
[tweetViewController setInitialText:str2];
// Create the completion handler block.
[tweetViewController setCompletionHandler:^(TWTweetComposeViewControllerResult result) {
//NSString *output;
switch (result) {
case TWTweetComposeViewControllerResultCancelled:
// The cancel button was tapped.
//output = #"Tweet cancelled.";
NSLog(#"Tweet cancelled");
break;
case TWTweetComposeViewControllerResultDone:
// The tweet was sent.
//output = #"Tweet done.";
NSLog(#"Tweet done");
break;
default:
break;
}
// Dismiss the tweet composition view controller.
[self dismissModalViewControllerAnimated:YES];
}];
// Present the tweet composition view controller modally.
[self presentModalViewController:tweetViewController animated:YES];
}
You simply need a variable that is available throughout your class
// ViewController.h
...
#interface ViewController : UIViewController {
double gpagoal;
}
Make sure it is properly initialized and updated as needed.

iPhone crash log

do you explain the foollowing crash log......
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController createAddressBookCopy]: unrecognized selector sent to instance 0x5908300'.
what does it mean?
my code is here....
-(NSString *)pathOfFile{
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *documentsDirectory=[paths objectAtIndex:0];
//lastName.text=[paths objectAtIndex:0];
return [documentsDirectory stringByAppendingFormat:#"contacts.plist"];
}
-(IBAction)createAddressBookCopy{
UIActionSheet *actionSheet=[[UIActionSheet alloc]
initWithTitle:#"Wanna create a copy of Addressbook?"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:#"Yeah!!!"
otherButtonTitles:nil];
[actionSheet showInView:self.view];
[actionSheet release];
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
NSMutableArray *masterList = [[NSMutableArray alloc] init];
for (int i = 0; i < nPeople; i++) {
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i);
CFStringRef fName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
CFStringRef lName = ABRecordCopyValue(ref, kABPersonLastNameProperty);
NSString *contactFirstLast = [NSString stringWithFormat: #"%#", (NSString *)lName];
CFRelease(fName);
CFRelease(lName);
[masterList addObject:contactFirstLast];
//[contactFirstLast release];
}
//self.list = masterList;
[masterList writeToFile:[self pathOfFile] atomically:YES];
[masterList release];
}
//creating action sheet
-(void)actionSheet:(UIActionSheet *) actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex{
if (buttonIndex!=[actionSheet cancelButtonIndex]) {
UIAlertView *alert=[[UIAlertView alloc]
initWithTitle:#"Copy creaeted."
message:#"New copy is contacts.plist"
delegate:self
cancelButtonTitle:#"DONE"
otherButtonTitles:nil
];
[alert show];
[alert release];
}
}
Check if your IBAction is connected properly. I think its not connected properly. Check if the declaration of the method in .h file is same.
You have sent the message createAddressBookCopy to a UIViewController object. The app crashed because UIViewController does not have a method of that name.
It means that you have some code that tried to call the createAddressBookCopy method on a UIViewController instance. According to the documentation, no such method exists, hence the crash.
That means that some object in your program trying to send createAddressBookCopy message to UIViewController, but this UIViewController object doesn't implement such method
UIViewController doesn't have a method called createAddressBookCopy. I suspect you have a UIViewController subclass which does have that method, but for some reason you're calling the super class. This sometimes happens if you're using interface builder and don't have your outlets hooked up correctly.