这里我需要隐藏电话号码、电子邮件、出生日期、周年纪念日和其他标签,以防这些字段没有值。我该怎么做?
最佳答案
多种方式,从最简单的开始:
self.emailLabel.hidden = YES;
但是您可能想要重新格式化 View 的其他部分以适应空白空间。为简单起见,您可以执行以下操作:
self.phoneLabel.frame = CGRectOffset(self.phoneLabel.frame, 0, -self.emailLabel.bounds.size.height);
...等等下面的任何内容。但是你可以看到这将如何变得乏味。下一个可能是最好的选择是 UITableView,它根据某些数据是否存在来调整它的部分计数。那会像这样。使用模型的各个部分及其值准备一个可变数组。
- (void)prepareModel {
self.model = [NSMutableArray array];
[self.model addObject:@[@"Name", @"Judy"]; // get "Judy" from your data
if (/* model has email */) {
[self.model addObject:@[@"Email", @"judy@gmail.com"]; // get email from your model
}
// and so on for conditional parts of your model
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.model.count;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
return self.model[section][0];
}
cellForRow 将使用 self.model[section][1]
初始化单元格。
关于iphone - 如何在 ios 中移动标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17120721/