I don't understand why the code isn't working, and nothing I found seems to be working. So I've come here for help. Ultimately, I want to be able to send my link to Safari whenever I click on the "View" button, and I want the link to be copied whenever I click on the "Copy" button.
Here's the code (under " - (void)viewDidLoad "):
NSMutableArray *sites = [[NSMutableArray alloc] initWithObjects:#"http://www.apple.com/", #"http://www.youtube.com/", #"http://maps.google.com/", #"http://ww.google.com/", #"http://www.stackoverflow.com/", nil];
self.cloudsendList = sites;
Here is the code (under " - (IBAction) touchUpInsideAction:(UIButton*)button "):
NSIndexPath* indexPath = [tableView indexPathForCell:sideSwipeCell];
NSUInteger index = [buttons indexOfObject:button];
NSDictionary* buttonInfo = [buttonData objectAtIndex:index];
if ([[buttonInfo objectForKey:#"title"] isEqualToString:#"View"]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat: #"%#", indexPath.row]]];
} else if ([[buttonInfo objectForKey:#"title"]isEqualToString:#"Copy"]) {
NSString *message = indexPath.row;
[UIPasteboard generalPasteboard].string = message;
Just to note, I am able to see the NSMutableArray data on each cell, I just can't grab it. I've also tried to insert "cloudsendList indexPath.row" instead of just "indexPath.row", but it didn't work. I hope this gives you enough information, and any bit of help would be really appreciated. Also, I apologize if I sound kind of noobish; I'm still sort of new to Objective-C programming. Thanks! :)
indexPath.row is an NSInteger, not the text at that location. This means your NSString *message is getting the integer value of the row you are on (0, 1, 2...). Try using that location as an index when pulling from your sites/cloudsendList array.
Ex.
NSString *message = [cloudsendList objectAtIndex:indexPath.row];
UPDATE:
To open the browser, use the same concept.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat: #"%#", [cloudsendList objectAtIndex:indexPath.row]]]];
Related
I have an emergency call app. When the user presses on the contact it calls them. Then the user has to return to the app to send the automated SMS. However I would like it that when pressed on the contact the user is taken to the message framework and once send is pressed it then calls the person. Here is the code so far.
- (NSString *)deviceLocation {
return [NSString stringWithFormat:#"Hi, you have been contacted as there has been an emergancy. Here is the location of the caller: Latitude: %f Longitude: %f . Please call for help to that location. From Kiddy Call the iPhone app. ", locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude];
}
#pragma mark - PictureListMainTableCellDelegate methods
-(void)pictureListMainTableCell:(PictureListMainTableCell *)cell wantsToCallNumber:(NSString *)number
{
if([MFMessageComposeViewController canSendText])
{
MFMessageComposeViewController *messageComposer =
[[MFMessageComposeViewController alloc] init];
NSString *message = (#"%#", [self deviceLocation]);
[messageComposer setBody:message];
messageComposer.recipients = [NSArray arrayWithObjects:number , nil];
messageComposer.messageComposeDelegate = self;
[self presentViewController:messageComposer animated:YES completion:nil];
NSLog(#"Texting telephone number [%#]", messageComposer);
}
NSString *urlString = [NSString stringWithFormat:#"tel://%#", number];
NSLog(#"calling telephone number [%#]", number);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
NSLog(#"%#", [self deviceLocation]);
}
Any solutions to this will be greatly appreciated.
You're doing:
messageComposer.messageComposeDelegate = self;
just define:
messageComposeViewController:didFinishWithResult
It will be called when someone finished editing text and you can get result out of second parameter.
MessageComposeResultCancelled,
MessageComposeResultSent,
MessageComposeResultFailed
And from this callback you can make a call.
To make a call use:
NSString *phoneNumber = [#"telprompt://" stringByAppendingString:#"123123123"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
or tel:// for calling without prompting.
I have a model that follows this:
Then I want to stock a city from a UITableView. The problem is, that I want to hold them in the iPhone (Database) until it reach 10, after that it erases the first and adds the last. I have the idea, but I can't just reach to add anything and i'm confused.
When I click a city, it pushes to the next view sending from a response JSON the id and the name of the city.. Thats ok. But I want to store those in order to make the same call but from another UITableView (under it) So it's like the "Last cities searched" something lik that.
I want to save the id,name and after that load it in the other tableView showing only the name. With that i'm Ok, but I can't reach to make the stock happend.
Code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
DetailTaxi *detailView = [[DetailTaxi alloc] initWithNibName:nil bundle:[NSBundle mainBundle]];
NSString *nomville = [[_jsonDict objectAtIndex:indexPath.row] objectForKey:#"label"];
NSString *idVille = [[_jsonDict objectAtIndex:indexPath.row] objectForKey:#"id"];
detailView.title = nomville;
detailView.idVille = idVille;
NSLog(#"Valor: %#", nomville);
NSLog(#"Valor: %#", idVille);
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSString *insert = [[NSString alloc] initWithFormat:#"%#,%#",idVille,nomville];
NSManagedObject *newVille;
NSArray *insertVilles = [insert componentsSeparatedByString:#","];
for(NSString *insert in insertVilles) {
newVille = [NSEntityDescription insertNewObjectForEntityForName:#"Ville" inManagedObjectContext:context];
[newVille setValue:[insertVilles objectAtIndex:0] forKey:#"id"];
[newVille setValue:[insertVilles objectAtIndex:1] forKey:#"nom"];
}
[self.navigationController pushViewController:detailView animated:YES];
}
Just add a new attribute of type NSDate which you set to the current date upon creating a new entry. Once you retrieve the cities again, use a sort descriptor to sort the cities by the time they were saved and use a fetch limit.
If deleting the previous cities is necessary, the date attribute will prove useful as well.
So here's what I'm working with.
I'm trying to get rid of the Three20 framework...but I'm not sure what I should replace this specifically with:
NSMutableArray *selectedPeople = [[NSMutableArray alloc] init];
NSArray *cells = [textField cells];
for (TTTableTextItem *cell in cells) {
NSDictionary *person = [textField.dataSource contactInfoAtIndex:[cell.URL integerValue]];
[selectedPeople addObject:person];
[AppPreferences incrementContactUsage:[[person objectForKey:#"abId"] intValue]];
}
I've got a textfield that is implemented similar to the Token field view in the Messages app. (using JSTokenField... I've replaced TTPickerView with that).
I'm fairly new to the iOS scene, and I'm working on an old project (trying to get it out of the gutter).
Thank you for the help in advance.
I have a signature page, were the user can sign their name.
It needs to then be saved to NSDictionary, but i want to call a List of the keys to be text in a TableView for each row or cell.
so:
"viewImage = saved as object to key:Random Number"
That parts somewhat easy, the hard part is when i call it on the other Page to the TableView.
It Exits the App with Error"SIGABRT". Now all my Delegates are in place and working...i believe.
now heres some example code:
FirstPage.m
UIImagePNGRepresentation(viewImage);
NSMutableArray *innerArray = [[NSMutableArray array]init];
[innerArray addObject:viewImage];
[SignatureSave setObject:innerArray forKey:#"5599"];
simple Enough, but doesnt give me an error.
SecondPage.m
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
FirstPage *appShare = (FirstPage *)[[UIApplication sharedApplication] delegate];
NSArray *dataDuplicate = [[NSArray alloc]init ];
dataDuplicate = [appShare.SignatureSave allKeysForObject:#"innerArray"];
static NSString *CellIdentifier = #"Cell";
NSLog(#"%#",dataDuplicate);
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero]autorelease];
}
if (dataDuplicate != nil) {
cell.textLabel.text = [dataDuplicate objectAtIndex:indexPath.row];
}
else
{
UIAlertView *CellAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Error Loading content, Try Again Later." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[CellAlert show];
[CellAlert release];
}
return cell;
}
#end
Now, How do i get the viewImage to save to the NSDictionary, to be able to call it on the SecondPage and display the name of the objects in the TableVIew?
I really don't understand whats your problem exactly.
first of all, is your dictionary a retained object?
//FirstPage.h
#property (nonatomic, retain) NSDictionary *SignatureSave;
//FirstPage.m
#synthesize SignatureSave;
…
UIImagePNGRepresentation(viewImage);
NSMutableArray *innerArray = [NSMutableArray array]; // using "array" is equivalent to alloc-init-autorelease
[innerArray addObject:viewImage];
[self.SignatureSave setObject:innerArray forKey:#"5599"];
// OR setting the array directly:
UIImagePNGRepresentation(viewImage);
NSArray *innerArray = [NSArray arrayWithObject:viewImage];
[self.SignatureSave setObject:innerArray forKey:#"5599"];
// OR even setting the image directly to the dictionary:
UIImagePNGRepresentation(viewImage);
[self.SignatureSave setObject:viewImage forKey:#"5599"];
now if you access the object by writing self. in front it will call the retain and your object will stay alive. Otherwise it would be autoreleased at the end of the method. This will fix the problem that your dictionary is maybe not present/available at table view creation and you don't have to use a singleton.
what are you trying to access with this code?
FirstPage *appShare = (FirstPage *)[[UIApplication sharedApplication] delegate];
with [[UIApplication sharedApplication] delegate] you get your application delegate (obviously). These are the MyAppNameAppDelegate files but you treat it as a FirstPage class.
Just NSLog() to check you get the right class, the one you expect.
NSLog(#"%#", [[[UIApplication sharedApplication] delegate] class]);
here you have a potential leak, you alloc-init but never release it:
NSArray *dataDuplicate = [[NSArray alloc]init ];
dataDuplicate = [appShare.SignatureSave allKeysForObject:#"innerArray"];
furthermore you can simplify it (will be autoreleased):
NSArray *dataDuplicate = [appShare.SignatureSave allKeysForObject:#"innerArray"];
and here you have another issue.
Why do you call all keys for the object #"innerArray"?
you don't have such an object and it's in many more cases wrong. innerArray was your previously named array in FirstPage.m but it is only for you as a developer to remember the variable better. After compilation it will have a cryptic name anyway. You could access your key #"5599" if you like but I don't think you want this. In your case you want to access all keys of the dictionary so simply call:
NSArray *dataDuplicate = [appShare.SignatureSave allKeys];
now you will have an array with all keys of your dictionary and you can access them like you do with objectAtIndex:.
NSString *keyName = [dataDuplicate objectAtIndex:indexPath.row];
cell.textLabel.text = keyName;
id theObject = [appShare.SignatureSave objectForKey:keyName]; // for example the image
Tell me if this solves your problems or tell me how I misunderstood your question.
I found the answer to this to be quit simple actually,
I ended up going with the Singleton Method instead of the Global Variable Method.
Now the Singleton Method looks terrifying but its quit simple, See here.
The main difference i noticed from the singleton method to the global method is,
Global method takes a lot of converting and re-converting.
Though the Singleton Method is working with a single object over many pages or classes.
Now i hope this will better assist people in the future also!
I want load the html data in webview. At the button click, it open the viewcontroller and load the html data in this viewcontroller (add web view in this view controller using Interface builder). When the html data not proper loading and i press the back button, at that time crash the app. i am not doing allocation & init webview in the coding. set IBOUTLET using Interface builder & bind it.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[connection release];
NSString *strResponce = [[NSString alloc] initWithData:jsonData_Info encoding:NSUTF8StringEncoding];
[jsonData_Info release];
NSError *error;
SBJSON *json = [[SBJSON new] autorelease];
self.jsonArray_Info=[json objectWithString:strResponce error:&error];
str_InfoDetail = [[self.jsonArray_Info objectAtIndex:0] valueForKey:#"Page"];
str_html = [NSString stringWithFormat:#"%#",str_InfoDetail];
NSString *temp;
temp = [NSString stringWithFormat:#"<html><head><style>body{background-color:transparent;}</style></head><body><span style='color:white'>%#</span></body></html>",str_html];
//web_Information = [[UIWebView alloc]init];
web_Information.backgroundColor=[UIColor clearColor];
web_Information.opaque= NO;
[web_Information loadHTMLString:temp baseURL:nil];
[act stopAnimating];
[strResponce release];
}
please give me any solution.
thanks.
Pls post some code and crash log if you need answers. By the look of it I think it may be because of implementation of UIWebView delegate in your class. I think when you navigate back you do not make the delegate nil which can cause the app to crash