gpt4 book ai didi

ios - 从 uitableview 隐藏特定 View

转载 作者:行者123 更新时间:2023-11-29 12:01:24 25 4
gpt4 key购买 nike

我有一个表格 View 。以下是我的 cellForRowAtIndexPath 代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

UITableViewCell *cell = nil;
cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@""];

if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:nil];
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
orderDetailsLabel = [[UILabel alloc]init];
shipmentStatusLabel = [[UILabel alloc]init];
ratingandFeedbackLabel = [[UILabel alloc]init];

HCSStarRatingView *starRatingView;

UILabel *suggestionsLabel;
UILabel *checkBoxLabel1;
UIButton *checkBoxButton1;
UIButton *saveButton;
UIImageView *checkbox1;
UITextView *feedBackTextView;

suggestionsLabel = [[UILabel alloc]init];

checkBoxLabel1 = [[UILabel alloc]init];


checkBoxButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
checkbox1 = [[UIImageView alloc]init];
feedBackTextView = [[UITextView alloc]init];

if (indexPath.row == 0)
{

ratingandFeedbackLabel.frame = CGRectMake(20, 5, 350, 20);
ratingandFeedbackLabel.text = [ratingandFeedbackArray objectAtIndex:indexPath.row];
ratingandFeedbackLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:14];

starRatingView = [[HCSStarRatingView alloc] initWithFrame:CGRectMake(20, 15, 100, 50)];
starRatingView.maximumValue = 5;
starRatingView.minimumValue = 0;
starRatingView.value = 0;
starRatingView.tintColor = [UIColor colorWithRed:254/255.0 green:174/255.0 blue:77/255.0 alpha:1];
starRatingView.backgroundColor = [UIColor clearColor];
[starRatingView addTarget:self action:@selector(didChangeValue:) forControlEvents:UIControlEventValueChanged];

}
else if (indexPath.row == 1)
{
checkbox1.frame = CGRectMake(20, 0, 20, 20);
checkbox1.image = [UIImage imageNamed:@"checkbox-nottick-60@2x.png"];
checkBoxButton1.frame = CGRectMake(20, 0, 20, 20);
[checkBoxButton1 addTarget:self action:@selector(checkBoxButton1Tapped:) forControlEvents:UIControlEventTouchUpInside];

suggestionsLabel.frame = CGRectMake(10, 185, 300, 30);
suggestionsLabel.text = @"Your feedback will help us make better *";
suggestionsLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:13];

CGRect screenRect = [[UIScreen mainScreen] bounds];

if (screenRect.size.height == 480)
{
tableView.scrollEnabled = YES;
feedBackTextView.frame = CGRectMake(18, 220, 285, 100);
saveButton.frame = CGRectMake(120, 330, 70, 30);

}

UIColor *borderColor = [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:1.0];
feedBackTextView.text = @"";

[saveButton setTitle:@"Save" forState:UIControlStateNormal];
[saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[saveButton addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];

}

tableView.tableFooterView = [UIView new];

[cell.contentView addSubview:orderDetailsLabel];
[cell.contentView addSubview:shipmentStatusLabel];
//[cell.contentView addSubview:starRatingImageView];
[cell.contentView addSubview:ratingandFeedbackLabel];
[cell.contentView addSubview:suggestionsLabel];

[cell.contentView addSubview:checkBoxButton1];

[cell.contentView addSubview:checkBoxLabel1];
[cell.contentView addSubview:feedBackTextView];
[cell.contentView addSubview:starRatingView];
[cell.contentView addSubview:saveButton];

return cell;
}

在调用的其他方法 receiveStarRatingData 中,我正在接收来自用户的状态代码。如果状态代码为 1,我不想显示复选框、建议标签、保存按钮和反馈 TextView 。如何隐藏它们或从方法 receiveStarRatingData 中删除它们?

最佳答案

您可以在 tableView Controller 中使用 bool 变量,例如 isStatusCodeOne :) 一旦您在 receiveStarRatingData 方法中收到数据,如果状态代码为 1,则将此变量设置为 true :) 并通过调用 self.tableView 重新加载 tableView。 reloadData()

一样处理 cellForRowatIndexpath 中的标签
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@""];

if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:nil];
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
orderDetailsLabel = [[UILabel alloc]init];
shipmentStatusLabel = [[UILabel alloc]init];
ratingandFeedbackLabel = [[UILabel alloc]init];

HCSStarRatingView *starRatingView;

UILabel *suggestionsLabel;
UILabel *checkBoxLabel1;
UIButton *checkBoxButton1;
UIButton *saveButton;
UIImageView *checkbox1;
UITextView *feedBackTextView;

if (!self.isStatusCodeOne) {
suggestionsLabel = [[UILabel alloc]init];

checkBoxLabel1 = [[UILabel alloc]init];


checkBoxButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
checkbox1 = [[UIImageView alloc]init];
feedBackTextView = [[UITextView alloc]init];
}

if (indexPath.row == 0)
{

ratingandFeedbackLabel.frame = CGRectMake(20, 5, 350, 20);
ratingandFeedbackLabel.text = [ratingandFeedbackArray objectAtIndex:indexPath.row];
ratingandFeedbackLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:14];

starRatingView = [[HCSStarRatingView alloc] initWithFrame:CGRectMake(20, 15, 100, 50)];
starRatingView.maximumValue = 5;
starRatingView.minimumValue = 0;
starRatingView.value = 0;
starRatingView.tintColor = [UIColor colorWithRed:254/255.0 green:174/255.0 blue:77/255.0 alpha:1];
starRatingView.backgroundColor = [UIColor clearColor];
[starRatingView addTarget:self action:@selector(didChangeValue:) forControlEvents:UIControlEventValueChanged];

}
else if (indexPath.row == 1)
{
if(!isStatusCodeOne){
checkbox1.frame = CGRectMake(20, 0, 20, 20);
checkbox1.image = [UIImage imageNamed:@"checkbox-nottick-60@2x.png"];
checkBoxButton1.frame = CGRectMake(20, 0, 20, 20);
[checkBoxButton1 addTarget:self action:@selector(checkBoxButton1Tapped:) forControlEvents:UIControlEventTouchUpInside];

suggestionsLabel.frame = CGRectMake(10, 185, 300, 30);
suggestionsLabel.text = @"Your feedback will help us make better *";
suggestionsLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:13];

}
CGRect screenRect = [[UIScreen mainScreen] bounds];

if (screenRect.size.height == 480)
{
tableView.scrollEnabled = YES;
feedBackTextView.frame = CGRectMake(18, 220, 285, 100);
saveButton.frame = CGRectMake(120, 330, 70, 30);

}

UIColor *borderColor = [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:1.0];
feedBackTextView.text = @"";

[saveButton setTitle:@"Save" forState:UIControlStateNormal];
[saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[saveButton addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];

}


}
tableView.tableFooterView = [UIView new];
[cell.contentView addSubview:orderDetailsLabel];
[cell.contentView addSubview:shipmentStatusLabel];
//[cell.contentView addSubview:starRatingImageView];
[cell.contentView addSubview:ratingandFeedbackLabel];
if(!isStatusCodeOne){
[cell.contentView addSubview:suggestionsLabel];

[cell.contentView addSubview:checkBoxButton1];

[cell.contentView addSubview:checkBoxLabel1];
[cell.contentView addSubview:feedBackTextView];
[cell.contentView addSubview:starRatingView];
[cell.contentView addSubview:saveButton];
}
return cell;
}

并在 receiveStarRatingData 方法调用 self.tableView.reloadData() 后设置 isStatusCodeOne :)

关于ios - 从 uitableview 隐藏特定 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36857897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com