我有一个tableview。我想从选定的单元格名称创建字符串。例如我的单元名称:行号1 - 行号2 - 行号3 - 行号4 - 行号5选中行号1 - 行号2 - 行号5 mystring值=选定项目行号1,行号2,Row No 5.当我取消选择Row No 1 mystring value = Selected items Row No 2,Row No 5或Row No 5,Row No 2.没关系。 这可能吗?如果可能,我该怎么办?谢谢。Xcode MultipleCellSelection选择名称
//编辑 我的代码在这里;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
tableData = [[NSMutableArray alloc] init];
[tableData retain];
for (int i=1; i<=10; i++)
{
NSString *rowInString= [[NSString alloc ]initWithFormat:@"Row No %d",i];
[tableData addObject:rowInString];
rowInString=nil;
}
_mytable.allowsMultipleSelectionDuringEditing = YES;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"self.Data count: %lu", (unsigned long)[tableData count]);
return tableData.count ;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *[email protected]"cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellidentifier];
if(cell==nil)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellidentifier];
}
NSString *cellValue;
cellValue=[tableData objectAtIndex:[indexPath row]];
[_mytable setEditing: YES];
cell.textLabel.text=cellValue;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *selectedText = @"Selected Items";
NSArray *selectedRows = [_mytable indexPathsForSelectedRows];
NSLog(@"%lu" , (unsigned long)selectedRows.count);
}
- (void)dealloc {
[_mytable release];
[super dealloc];
}
@end
是的,这是可能的。 –
@LyndseyScott我该怎么做。你可以分享示例代码吗?谢谢。 –
你必须在人们帮助你之前展示你想要达到的目标。 – MattD