ios - 表格 View 单元格仅在滚动一次后显示实际数据
<p><pre><code>NSArray *sectionArray;
int sectionCount=0;
NSDictionary *orderedData;
NSString *checkInStr, *checkOutStr;
NSString *govtTaxes, *enhancementTotal, *grandTotal;
- (void)viewDidLoad {
;
;
;
}
- (void)didReceiveMemoryWarning {
;
}
-(void)viewDidDisappear:(BOOL)animated {
if(doesSendNotification){
NSLog(@"summary view disappeared");
[ postNotificationName:@"SummaryViewDismissedNotification" object:self];
}
}
-(void)viewWillAppear:(BOOL)animated {
;
}
-(void)setupTable {
self.bookingsTableView.rowHeight = UITableViewAutomaticDimension;
self.bookingsTableView.estimatedRowHeight = 50.0;
sectionArray = [ getTableSections:self.s_sendEnhancementServerDict];
orderedData = [ getOrderedData:self.s_sendEnhancementServerDict];
;
}
#pragma mark- UITableview delegate and datasource methods
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if(section==0){
return 3;
} else if (section>0 && section<(sectionCount-1)){
int rows=(int)[] count];
return rows;
} else {
return 4;
}
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return (NSString*);
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdentifier;
UITableViewCell *cell;
// UITableView *table = (UITableView*);
if (indexPath.section==0 && indexPath.row>=0 && indexPath.row<=2) {
cellIdentifier =@"SplitCell";
cell = ;
if (cell == nil) {
cell = [ initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
UILabel *l1 = (UILabel*);
UILabel *l2 = (UILabel*);
if(indexPath.row==0){
l1.attributedText = ;
l2.attributedText = ;
} else if(indexPath.row==1){
l1.attributedText = ;
l2.attributedText = ;
} else if(indexPath.row==2){
l1.attributedText = ;
l2.attributedText = ;
}
} else if (indexPath.section>0 && indexPath.section<(sectionCount-1)) {
// for(int i=0;i<5;i++){
cellIdentifier=@"VerticalLabelCell";
cell = ;
if (cell == nil) {
cell = [ initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
UILabel *l3 = (UILabel*);
UILabel *l4 = (UILabel*);
l3.layer.backgroundColor = GOLDEN_COLOR.CGColor;
NSArray *roomTypeArray = ];
NSDictionary *roomD = ;
NSString *header = ;
NSAttributedString *sH = [ initWithString: attributes:@{NSFontAttributeName:ARIAL_FONT_BOLD}];
l3.attributedText = sH;
int roomCount = [(NSNumber*) intValue];
NSMutableAttributedString *labelText = [ init];
for(int i=0;i<roomCount;i++){
NSString *roomNo = ;
NSAttributedString *s = [ initWithString:roomNo attributes:@{NSFontAttributeName:ARIAL_FONT_BOLD, NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle)}];
;
NSString *adults = ,];
NSAttributedString *s1 = [ initWithString:adults attributes:@{NSFontAttributeName:ARIAL_FONT_BOLD}];
;
NSArray *enhanc = [(NSArray*) objectAtIndex:i];
for(int i=0;i<;i++){
]]];
}
l4.attributedText = labelText;
}
} else if(indexPath.section==(sectionCount-1)){
cellIdentifier =@"SplitCell";
cell = ;
if (cell == nil) {
cell = [ initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
UILabel *l1 = (UILabel*);
UILabel *l2 = (UILabel*);
if(indexPath.row==0){
l1.attributedText = ;
l2.attributedText = ];
}else if(indexPath.row==1){
l1.attributedText = ;
l2.attributedText = ];
}else if(indexPath.row==2){
l1.attributedText = ;
l2.attributedText = ];
}else if(indexPath.row==3){
l1.attributedText = ;
l2.attributedText = ];
}
}
return cell;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
sectionCount = (int);
return sectionCount;
}
-(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
view.tintColor = GOLDEN_COLOR;
}
-(NSAttributedString*)getStyledString:(NSString*)input {
NSAttributedString *str = [ initWithString:input attributes:@{NSForegroundColorAttributeName:GOLDEN_COLOR, NSFontAttributeName:ARIAL_FONT}];
return str;
}
-(NSAttributedString*)getStyledString1:(NSString*)input {
NSAttributedString *str = [ initWithString:input attributes:@{NSFontAttributeName:ARIAL_FONT_BOLD}];
return str;
}
-(NSAttributedString*)getStyledString2:(NSString*)input {
NSAttributedString *str = [ initWithString:input attributes:@{NSFontAttributeName:ARIAL_FONT}];
return str;
}
</code></pre>
<p>我制作了一个 ViewController 并在其中添加了一个表格 View 。一些数据填充在单元格中,然后显示。
当我运行它时,最初我在单元格中看不到任何数据。但是当表格 View 滚动时,单元格开始显示实际数据。我不明白可能是什么原因。请大家指点???</p>
<p>我想动态调整单元格的大小,因为数据可以是随机大小。数据只在滚动一次后显示。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>此问题与使用 UITableViewAutomaticDimension 有关,其他地方也有报告。所以这行代码,解决了我的问题:</p>
<pre><code>-(void)viewDidAppear:(BOOL)animated {
;
}
</code></pre>
<p>这只是在显示之前重新加载所有表格部分和行。所以用户不会遇到空白行。引用:<a href="http://www.appcoda.com/self-sizing-cells/" rel="noreferrer noopener nofollow">http://www.appcoda.com/self-sizing-cells/</a> </p></p>
<p style="font-size: 20px;">关于ios - 表格 View 单元格仅在滚动一次后显示实际数据,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/38505598/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/38505598/
</a>
</p>
页:
[1]