Ios DidDecreateRowatineXpath在目标c中未收到调用
我是iOS新手,在选择和取消选择表格视图单元格方面面临问题。对于取消选择,我使用了DIDDEXECROWATINDEXPATH,但它没有得到调用 我的代码是这样的Ios DidDecreateRowatineXpath在目标c中未收到调用,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我是iOS新手,在选择和取消选择表格视图单元格方面面临问题。对于取消选择,我使用了DIDDEXECROWATINDEXPATH,但它没有得到调用 我的代码是这样的 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewC
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text=[NSString stringWithFormat:@"%@",[reportshortActivityarray objectAtIndex:indexPath.row]];
if([Selectedarray containsObject:[reportshortActivityarray objectAtIndex:indexPath.row]])
{
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
}
else
{
[cell setAccessoryType:UITableViewCellAccessoryNone];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [activitytable cellForRowAtIndexPath:indexPath];
if(![Selectedarray containsObject:[reportshortActivityarray objectAtIndex:indexPath.row]]){
[Selectedarray addObject:[reportshortActivityarray objectAtIndex:indexPath.row]];
txtactivity.text = [Selectedarray componentsJoinedByString:@","];
DefaultActivityString=txtactivity.text;
}
NSLog(@"Selected Value =%@",txtactivity.text);
if(![SelectedIDarray containsObject:[reportidActivityarray objectAtIndex:indexPath.row]]){
[SelectedIDarray addObject:[reportidActivityarray objectAtIndex:indexPath.row]];
lblactivity.text = [SelectedIDarray componentsJoinedByString:@","];
}
NSLog(@"Selected Value =%@",lblactivity.text);
if (cell.selected) {
// ... Uncheck
[activitytable deselectRowAtIndexPath:indexPath animated:YES];
}
[[activitytable cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];
activitytable.hidden=NO;
}
- (void)tableView:(UITableView *)tableView didDeSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if([Selectedarray containsObject:[reportshortActivityarray objectAtIndex:indexPath.row]]){
[Selectedarray removeObject:[reportshortActivityarray objectAtIndex:indexPath.row]];
txtactivity.text = [Selectedarray componentsJoinedByString:@","];
}
if([SelectedIDarray containsObject:[reportidActivityarray objectAtIndex:indexPath.row]]){
[SelectedIDarray removeObject:[reportidActivityarray objectAtIndex:indexPath.row]];
lblactivity.text = [SelectedIDarray componentsJoinedByString:@","];
}
NSLog(@"Selected Value =%@",lblactivity.text);
[[activitytable cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryNone];
activitytable.hidden=NO;
}
我使用这段代码来选择和取消选择它,选择正确,但不取消选择
如图所示,我可以选择行,但不能取消选择。只需写入方法即可
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
...
[tableView deselectRowAtIndexPath:indexPath animated:YES];
...
}
强烈建议使用代码补全。这将为您提供正确的拼写(大小写很重要!):
…取消选择…
请注意小写的select如果我没记错的话,有一个反直觉的机制:除非启用TableView的allowsMultipleSelection属性,否则该协议方法将不会启动。如果您还没有解决,请尝试一下。我检查了您的代码,我认为您想要制作一个菜单,当单击菜单项时,调用didselectrow方法并将单元格的accessorytype更改为mark,当第二次单击相同或不同的项时,将accessorytype更改为none 无论您是第一次还是第二次单击项,如果您想更改单元格的accessorytype,请在datasource数组中为model做一个属性布尔标记,以存储菜单项的select状态
在
didselectrow
方法中,更改模型的标记,然后重新加载数据。在row
方法中不需要任何代码。您在理解方法时出现了一些错误DIDROW
您试图创建所选单元格的数组吗?但是在这里,你犯了打字错误,因为用户vadian建议它的didderowatinexpath
@vaibhav ok让我检查一下……你能告诉我如何设置代理吗?看起来您的数据源正在运行,但tableview.delegate的行为异常这可能会因为“排版错误”而被搁置。此外,他正在通过编程方式取消选择[activitytable DeserrowAtIndexPath:indexPath animated:YES]
这意味着可能不会调用didDecelrowatindexpath
。@vadian现在完成了。如果(cell.selected){/…取消选中[activitytable Decelrowatindexpath:Indexath animated:YES];}和小写s,我就删除了这一行,谢谢兄弟。