我有一個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