2011-12-12 209 views
-1
- (IBAction)doUpload:(id)sender { 
    NSMutableString *str = [[NSMutableString alloc] initWithString:@"Selected: "]; 
    for(int i = 0; i < [appDelegate.notesArray count]; i++) { 
     // UPLOAD STRINGS HERE 
     if(selected[i]) { 
      [str appendFormat:@"%@ ", [appDelegate.notesArray objectAtIndex:i]]; 
     } 
    } 

    UploadView *uploadview = (UploadView *)self.view; 
    if(uploadview != nil) { 
     [m_owner uploadString:str]; 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Selected Values"  message:str delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 
     // [self dismissModalViewControllerAnimated:YES]; 
    } 
} 

在上面的代码中,str变量包含tableview单元格中的一些值。我的桌面视图已启用多项选择,因此str包含多个值。分隔字符串?

此代码:

[m_owner uploadString:str]; 

用于上传到gdoc,但是当str包含多个值,它同时上传所有的值。我想分开这些值,然后逐个上传它们。

我该怎么做?

+0

什么是gdoc?什么是m_owner?为什么你不能单独调用每个字符串的uploadString,而不是将它们全部附加到一个字符串中? – Brian

+0

@Brian gdoc的意思是谷歌文件,m_orwner是类googledoc_loginpge,即男士m_orwner是登录用户 – ICoder

回答

0

如果您只是想分离组件,您可以尝试使用componentsSeperatedByString:方法。因此,您将获得可用于迭代上传的一组对象。

[yourString componentsSeparatedByString:separatorString]; 

希望这有助于。

+0

先生,什么是分隔符字符串?我在str中的值。 – ICoder

+0

if(selected [i])[str appendFormat:@“%@”,[appDelegate.notesArray objectAtIndex:i]]; [str componentsSeparatedByString:@“,”];它是否正确? – ICoder

+0

separatorString是可以用来标识组件的字符串。它可以是任何字符串,你用来追加字符串 – visakh7

1
NSString *str = @"Hi ! I am iPhone Developer"; 

NSArray *myWords = [str componentsSeparatedByString:@"!"]; 

NSString *str1 = [NSString stringWithFormat:@"%@",[myWords objectAtIndex:0]]; 

NSString *str2 = [NSString stringWithFormat:@"%@",[myWords objectAtIndex:1]]; 

NSLog(@"%@",str1); 

NSLog(@"%@",str2); 

你会发现在登录这样

我iPhone开发