我有这个代码 NSString * localStringValue;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
localStringValue = [m_textfield cellForRowAtIndexPath:indexPath].textLabel.text;
localStringValue = [m_textfield cellForRowAtIndexPath:indexPath].detailTextLabel.text;
NSArray* toReload = [NSArray arrayWithObjects: indexPath, self.selectedIndexPath, nil];
self.selectedIndexPath = indexPath;
if ([[tableView cellForRowAtIndexPath:indexPath] accessoryType] == UITableViewCellAccessoryCheckmark){
UploadView *uploadview = (UploadView *)self.view;
if (uploadview != nil)
{
[m_owner uploadString:localStringValue];
//[self dismissModalViewControllerAnimated:YES];
}
[[m_textfield cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryNone];
}
else {
[[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];
}
}
在这段代码中我正在将localStringValue同步到google-doc,当我点击单元格时,如果复选标记在那里.localStringValue包含tableview单元格中的值。此时所有事情都正常工作。但我需要的是我想要将此值传递给按钮单击,这意味着如果用户选择多行,我想要localStringValue中的所有值并通过此代码传递它
- (IBAction)doUpload:(id)sender
{
UploadView *uploadview = (UploadView *)self.view;
if (uploadview != nil)
{
[m_owner uploadString:@""];
//[self dismissModalViewControllerAnimated:YES];
}
}
我想在[m_owner uploadString:localstringvalue];
中传递localstringvalue
这该怎么做?
提前谢谢。
答案 0 :(得分:1)
您可以创建NSMutableArray
作为类变量,并且可以将字符串添加到didSelectRowAtIndexPath
上的字符串。稍后点击按钮,您可以处理NSMutableArray
逐个获取字符串并将其发送到google-doc ...等。
答案 1 :(得分:0)
您需要更新
- (void)doUpload:(NSString*)stringValue
{
UploadView *uploadview = (UploadView *)self.view;
if (uploadview != nil)
{
[m_owner uploadString:localstringvalue];
//[self dismissModalViewControllerAnimated:YES];
}
}
还有一件事
localStringValue = [m_textfield cellForRowAtIndexPath:indexPath].textLabel.text
//再次分配字符串,这条线没有任何意义。