2012-03-29 86 views
1

我有一個應用程序,可以分享Notes到Evernote,它可以正常工作,我可以上傳和下載我的筆記Evernote到應用程序中,我有一個註釋標題和註釋主題,我上傳了Notes to evernote viz UITableview controller.Textlabel.text是註釋的標題和detailtextlabel.text是註釋subject.i只有正確得到Notesubject的意思是,如果我在tableview中有兩個註釋標題,就像這個formmate 1)title:firstitle,notesubject: firstNotessubject 2)title:secondtitle,notesubject:secondNotessubject ,,然後我按上傳按鈕它將音符上傳到evernote,但是標題仍然是第一個只有註釋的,像這個formmate 1)title:firstitle,notesubject:firstNotessubject 2)title: firsttitle,notesubject:secondNotessubject.my代碼爲uplode按鈕是UITableview疑惑

-(IBAction)sendNoteEvernote:(id)sender{ 
NSMutableString *strtitle = [[NSMutableString alloc] initWithString:@""]; 
    for (int t = 0; t<[appDelegate.indexArray count]; t++) { 
     NSString * aStringtitle = [[NSString alloc] initWithString:[appDelegate.indexArray objectAtIndex:t]] ; 

    note.title =aStringtitle; 
    } 
     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]; 
      // [note setTitle:aStringtitle]; 
      // [note setResources:resources]; 

      // Saving the note on the Evernote servers 
      // Simple error management 
      @try { 
       [[eversingleton sharedInstance] createNote:note]; 
       _acteverbackup.hidden = YES; 
       _actimageeverbackup.hidden =YES; 
      } 
      @catch (EDAMUserException * e) { 
       _acteverbackup.hidden = YES; 
       _actimageeverbackup.hidden =YES; 
       NSString * errorMessage = [NSString stringWithFormat:@"Error saving note: error code %i", [e errorCode]]; 
       proAlertView *alert = [[proAlertView alloc]initWithTitle:@"Evernote" message:errorMessage delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil]; 
       [alert setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0] withStrokeColor:[UIColor colorWithHue:0.0 saturation:0.0 brightness:0.0 alpha:1.0]]; 
       [alert show]; 
       [alert release];  return; 
      } 

在上面的代碼中appdelegate.indexarray是標題和appdelegate.notearray是主題..我的UItableview代碼看起來像這樣。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 


// Customize the number of rows in the table view. 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return[appDelegate.notesArray count]; 
} 
/*-(UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypesForRowWithIndexPath:(NSIndexPath *)indexPath 
{ 

return UITableViewCellAccessoryCheckmark; 

}*/ 

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSUInteger row = [indexPath row]; 
    NSString *CellIdentifier; 
    CellIdentifier=[NSString stringWithFormat:@"cell %d",indexPath.row]; 


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];  
    if (cell == nil) { 

     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
     cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap; 
     cell.detailTextLabel.numberOfLines = 0; 
     UIImageView* img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"[email protected]"]]; 
     [cell setBackgroundView:img]; 
     [img release]; 
     count++; 
    } 
    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]; 


    //NSMutableString *notes=[[NSMutableString alloc]initWithString:[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]; 
    //textView.text=notes; 

    //[notes release]; 

    cell.backgroundColor=[UIColor clearColor]; 
    cell.accessoryType = UITableViewCellAccessoryNone; 



    return cell; 
} 

請問我的代碼中有什麼錯誤,請幫我做到這一點。 由於事先

+0

不明白你的問題.. – Hiren 2012-03-29 10:57:09

+0

@CocoaMatters標題保持不變,這是我的問題。只有一個標題被顯示,並且該標題成爲evry note的標題,但註釋主題更改 – stackiphone 2012-03-29 11:06:03

+0

如果您取消註釋行[注意setTitle:aStringtitle];'?會發生什麼? – 2012-03-29 11:13:48

回答

1

嘗試改變行:

NSMutableString *strr = [[NSMutableString alloc] initWithString:[appDelegate.indexArray objectAtIndex:indexPath.section]]; 

到:

NSMutableString *strr = [[NSMutableString alloc] initWithString:[appDelegate.indexArray objectAtIndex: row]]; 

而且擺脫了:

NSUInteger row = [indexPath row]; 
NSString *CellIdentifier; 
CellIdentifier = [NSString stringWithFormat:@"cell %d",indexPath.row]; 

簡單地使用:

CellIdentifier = @"noteCellIdentifier"; 

這與你的問題沒有任何關係,但它是單元重用的全部內容。

編輯:

這部分代碼看起來也suspitious:

for (int t = 0; t<[appDelegate.indexArray count]; t++) { 
    NSString * aStringtitle = [[NSString alloc] initWithString:[appDelegate.indexArray objectAtIndex:t]] ; 
    note.title =aStringtitle; 
} 

目前尚不清楚你想要做什麼,但你可能會想這個移動到:

for (int i = 0; i<[appDelegate.notesArray count]; i++) { 
    NSString * aStringtitle = [[NSString alloc] initWithString:[appDelegate.indexArray objectAtIndex:i]]; //note: t changed to i 
    note.title =aStringtitle; 

    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); 
    //.... 
+0

謝謝,讓我再次檢查 – stackiphone 2012-03-29 12:11:15

+0

同樣的問題..標題沒有改變它提醒所有筆記主題相同 – stackiphone 2012-03-29 12:18:46

+0

我不能beleve爲什麼會發生這種情況,我正確地從detaillabel獲得notesubject,並且我使用與textlabel.text相同的formate作爲我們的標題。但沒有運氣 – stackiphone 2012-03-29 12:23:26