I am in a problem with some text sharing to evernote,sharing evernote is success,but here is my current situation with code. I have a UITableView
which has some text and title for that corresponding text. When the share button is clicked it will share the text onebyone to evernote website, but the title remains static. There I get the first title name along with diffrent text. My code for this is in my tableview in rowAtIndexPath
NSMutableString *strr=[[NSMutableString alloc]initWithString:[appDelegate.indexArray objectAtIndex:indexPath.section]];
cell.textLabel.text =strr ;
cell.textLabel.text = [appDelegate.indexArray objectAtIndex:row];
cell.textLabel.font = [UIFont fontWithName:@"Georgia" size:14.0];
cell.textLabel.textColor = [UIColor brownColor];
[appDelegate.notesArray objectAtIndex:row]];
//cell.detailTextLabel.text =notes;
cell.detailTextLabel.font = [UIFont fontWithName:@"Georgia" size:14.0];
cell.detailTextLabel.textColor = [UIColor darkGrayColor];
cell.detailTextLabel.text = [appDelegate.notesArray objectAtIndex:row];
appDelegate.indexArray
is the title content for each cell and appDelegate.notesArray
has the textnote for the corresponding titles.
In shareButton click:
NSMutableString *str = [[NSMutableString alloc] initWithString:@"NOTES:"];
for (int i = 0; i<[appDelegate.notesArray count]; i++) {
NSString * aString = [[NSString alloc] initWithString:[appDelegate.notesArray objectAtIndex:i]] ;
NSString * ENML= [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">\n<en-note>%@",aString];
ENML = [NSString stringWithFormat:@"%@%@", ENML, @"</en-note>"];
NSLog(@"%@", ENML);
// Adding the content & resources to the note
[note setContent:ENML];
This will give the one by one upload of notetext.but for title I include this code
NSMutableString *strtitle = [[NSMutableString alloc] initWithString:@"myBibleApp"];
for (int i = 0; i<[appDelegate.indexArray count];i++ ) {
NSString * aStringtitle = [[NSString alloc] initWithString:[appDelegate.indexArray objectAtIndex:i]] ;
/* NSString *ENMLtitle = [NSString stringWithFormat:@"%@%@", aStringtitle];
NSLog(@"%@", ENMLtitle);*/
note.title = aStringtitle;
But here is my problem it uplode the title and text in double. That means, I have one text with title. When I click the sharebutton it uploads two times.1=2,2=4,3=6 like that. Nut only addding the title I get this problem. If I put the title static,note.title =@"statictitle". It will not repeat the upload. How can I append the string in correct way? Please help me. Thanks in advance.
The same + operator you use for adding two numbers can be used to concatenate two strings. You can also use += , where a += b is a shorthand for a = a + b .
To concatenate two strings into a new string: NSString *string1 = @"This is"; NSString *string2 = @" a test.
You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs. For string variables, concatenation occurs only at run time.
Two things I noted:
The use of NSMutableString is not needed. Just write for the first case
cell.textLabel.text = [appDelegate.indexArray objectAtIndex:indexPath.section];
For the 2 other cases you don't use the string at all (or it's not shown in your code).
In the for-loops, you're always overwriting aString and aStringtitle, and that even with a new alloc. Appending goes like this:
NSString *aString = @"";
for ...
aString = [aString stringByAppendingString:[appDelegate.indexArray objectAtIndex:i]];
or
aString = [aString stringByAppendingFormat:@" %@", [appDelegate.indexArray objectAtIndex:i]];
Check the NSString Class Reference for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With