Uitableview 如何在iOS应用程序中存储UIButton的状态
我试着在这里读一些关于stackover的帖子,但我不明白如何解决我的问题 我有一个tableview Dynamics,我在tableview中使用parse.com获取gestionie数据。我有一个自定义单元格,其中有一个按钮,在用户被选中时发送朋友请求 还有一个查询调用所有已提交的好友请求。。。一旦这些需求显示出来,各种用户的查询按钮(在Tableview中)就会改变颜色 到目前为止还不错。。。唯一的问题是,我似乎无法存储按钮的状态。。。例如: 用户希望发送“A”好友请求,此时按钮的颜色会改变,但当tableView滚动时,按钮会再次返回到原始颜色,就像从未单击过一样 我怎样才能解决这个问题 资料: 此按钮的操作位于自定义单元格(带有类)中,并引用主视图控制器中的两个委托Uitableview 如何在iOS应用程序中存储UIButton的状态,uitableview,uibutton,Uitableview,Uibutton,我试着在这里读一些关于stackover的帖子,但我不明白如何解决我的问题 我有一个tableview Dynamics,我在tableview中使用parse.com获取gestionie数据。我有一个自定义单元格,其中有一个按钮,在用户被选中时发送朋友请求 还有一个查询调用所有已提交的好友请求。。。一旦这些需求显示出来,各种用户的查询按钮(在Tableview中)就会改变颜色 到目前为止还不错。。。唯一的问题是,我似乎无法存储按钮的状态。。。例如: 用户希望发送“A”好友请求,此时按钮的颜色
-(UITableViewCell * )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"cell";
NPCustomFindUserCell *cell =[tableViewFindUser dequeueReusableCellWithIdentifier:CellIdentifier];
if ([self.cellsCurrentlyEditing containsObject:indexPath]) {
[cell openCell];
}
cell.delegate = self;
cell.addUserButton.tag = indexPath.row;
PFUser *user = [self.userArray objectAtIndex:indexPath.row];
if (!isFiltered) {
PFObject *object = [userArray objectAtIndex:indexPath.row];
if (![self Is_InAttesa:user]) {
cell.addUserButton.tintColor = [UIColor colorWithRed:(167/255.0) green:(103/255.0) blue:(91/255.0) alpha:(1)];
}
else {
cell.addUserButton.tintColor = [UIColor grayColor];
}
cell.user_photoProfile.image = [UIImage imageNamed:@"camera"];
cell.user_photoProfile.layer.masksToBounds = YES;
cell.user_photoProfile.layer.cornerRadius = 3.0f;
cell.user_photoProfile.contentMode = UIViewContentModeScaleAspectFill;
cell.user_photoProfile.file = [object objectForKey:NPUserKey_PHOTOPROFILE];
[cell.user_photoProfile loadInBackground];
NSString *nameText = [object objectForKey:NPUserKey_NOMECOGNOME];
cell.label_UserNomeCognome.text = nameText;
cell.itemText = nameText;
}
else {
PFObject *OggettiFiltrati = [userFiltrati objectAtIndex:indexPath.row];
cell.user_photoProfile.file = [OggettiFiltrati objectForKey:NPUserKey_PHOTOPROFILE];
cell.user_photoProfile.image = [UIImage imageNamed:@"camera"];
[cell.user_photoProfile.layer setMasksToBounds:YES];
[cell.user_photoProfile .layer setCornerRadius:5.0f];
cell.user_photoProfile.contentMode = UIViewContentModeScaleAspectFill;
[cell.user_photoProfile loadInBackground];
NSString *str = [OggettiFiltrati objectForKey:NPUserKey_NOMECOGNOME];
cell.label_UserNomeCognome.text = str;
cell.itemText = str;
}
return cell;
}
您需要根据填充单元格的数据模型来确定单元格的状态。您的模型中应该有一些内容向单元格指示按钮应该处于活动/禁用状态等。您不应该将数据存储在表视图单元格中,因为当这些单元格从视图中滚出,然后又滚回视图时,这些单元格可能会被重新用于其他内容。你必须在你的数据模型中存储你的按钮属性。感谢游戏,不幸的是我需要更多的信息。我看到很多人在讨论这个问题,但我不知道如何在我的数据库中以正确的方式实现它model@rory,您将要对MVC模式进行研究。一旦您理解了MVC模式,您就会明白这意味着什么。