gpt4 book ai didi

iphone - 如何将 UITableview 行中的多个选定值共享到 facebook 或 googledoc?

转载 作者:行者123 更新时间:2023-12-03 20:53:09 25 4
gpt4 key购买 nike

大家好,我有一个圣经应用程序,用户可以创建笔记并将其与 googledoc 同步。我为此完成了所有编码,并在 TextView 中测试了示例笔记,并传递了 TextView 中的值进行上传,它成功了,但我的要求是我想从 tableview 单元格而不是 textview 获取值,而且我有一个使用复选标记的多选 tableview,并且如果用户选择行的多项选择,我想同步。我的代码是

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [appDelegate.indexArray count];
}


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

return UITableViewCellAccessoryCheckmark;

}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

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:@"bgCELL3@2X-1"]];
[cell setBackgroundView:img];
[img release];
count++;
}

NSMutableString *str=[[NSMutableString alloc]initWithString:[appDelegate.indexArray objectAtIndex:indexPath.section]];
cell.textLabel.text =str ;
cell.textLabel.font = [UIFont fontWithName:@"Georgia" size:14.0];
cell.textLabel.textColor = [UIColor brownColor];

NSMutableString *notes=[[NSMutableString alloc]initWithString:[appDelegate.notesArray objectAtIndex:indexPath.section]];
cell.detailTextLabel.text =notes;
cell.detailTextLabel.font = [UIFont fontWithName:@"Georgia" size:14.0];
cell.detailTextLabel.textColor = [UIColor darkGrayColor];
[notes release];

cell.backgroundColor=[UIColor clearColor];

return cell;
}

上面的代码是针对UITableview单元格的

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSArray* toReload = [NSArray arrayWithObjects: indexPath, self.selectedIndexPath, nil];
self.selectedIndexPath = indexPath;
if ([[tableView cellForRowAtIndexPath:indexPath] accessoryType] == UITableViewCellAccessoryCheckmark){

[[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryNone];
}

else {

[[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];

}

}

以上为选择代码

- (IBAction)doUpload:(id)sender
{
UploadView *uploadview = (UploadView *)self.view;
if (uploadview != nil)
{
[m_owner uploadString:@""];
//[self dismissModalViewControllerAnimated:YES];
}

}

这是上传按钮代码,我想从 [m_owner uploadString:here i want to pass the value]; 中的 uitableview 传递多个或单个值;

编辑:

- (IBAction)doUpload:(id)sender
{
NSMutableArray *rowsToBeDeleted = [[NSMutableArray alloc] init];
NSMutableArray *indexPaths = [[NSMutableArray alloc] init];
int index = 0;


for (NSNumber *rowSelected in appDelegate.notesArray)
{
if ([rowSelected boolValue])
{

[rowsToBeDeleted addObject:[appDelegate.notesArray objectAtIndex:index]];
NSUInteger pathSource[2] = {0, index};
NSIndexPath *path = [NSIndexPath indexPathWithIndexes:pathSource length:2];

[indexPaths addObject:path];
UploadView *uploadview = (UploadView *)self.view;
if (uploadview != nil)
{
[m_owner uploadString:path];
//[self dismissModalViewControllerAnimated:YES];
}


}
index++;




}

最佳答案

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (inPseudoEditMode)
{
BOOL selected = [[selectedArray objectAtIndex:[indexPath row]] boolValue];
[selectedArray replaceObjectAtIndex:[indexPath row] withObject:[NSNumber numberWithBool:!selected]];
[self.m_PTableView reloadData];
}

}

名为 selectedArray 的数组将包含 UITableView 中选定单元格的索引。

NSMutableArray *rowsToBeDeleted = [[NSMutableArray alloc] init];
NSMutableArray *indexPaths = [[NSMutableArray alloc] init];
int index = 0;


for (NSNumber *rowSelected in selectedArray)
{
if ([rowSelected boolValue])
{

[rowsToBeDeleted addObject:[rootDirectoryFileArray objectAtIndex:index]];
NSUInteger pathSource[2] = {0, index};
NSIndexPath *path = [NSIndexPath indexPathWithIndexes:pathSource length:2];

[indexPaths addObject:path];
}
index++;

}
}

关于iphone - 如何将 UITableview 行中的多个选定值共享到 facebook 或 googledoc?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8427003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com