【发布时间】:2014-12-24 21:02:14
【问题描述】:
我有一个表格视图。我想从选定的单元格名称创建字符串。 For example My Cell names : Row No 1 - Row No 2 - Row No 3 - Row No 4 - Row No 5. When selected Row No 1 - Row No 2 - Row No 5 mystring value = Selected Items Row No 1 , Row No 2,第 5 行。当我取消选择第 1 行时,我的字符串值 = 所选项目第 2 行,第 5 行或第 5 行,第 2 行。没关系。 是否可以?如果可能的话我该怎么办?谢谢。
//编辑 我的代码在这里;
- (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 *cellidentifier=@"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 我该怎么做。你能分享示例代码吗?谢谢。
-
在人们帮助你之前,你必须展示你为达到你想要的目标所做的努力。
-
如果用户选择五 - 二 - 三,文本应该是什么?会是五二三还是二三五
-
没关系。只是我想看到相同的字符串。
-
在下面查看我的答案。它适用于多项选择。
标签: ios iphone multipleselection