0

サブビューに表示されるラベルがあります。解析時にNSStringからラベルのテキストを取得しました。しかし、テキストを表示しようとしましたが、うまくいかないようです。テキストは表示されません。

これが私のコードです。これを解決する方法を知っている場合は、私に知らせてください:

PFQuery *query = [PFQuery queryWithClassName:@"myapp"];
[query getObjectInBackgroundWithId:@"myId"
                             block:^(PFObject *textu, NSError *error) {
                                 if (!error) {

                                     CGRect infoLabelRect = CGRectMake(10, 250, 260, 350);
                                     UILabel *infoLabel = [[UILabel alloc] initWithFrame:infoLabelRect];


                                     NSString *text = [textu objectForKey:@"newstext"];
                                     UIFont *font = nil;
                                     CGFloat points = 17;
                                     CGFloat maxHeight = infoLabel.frame.size.height;
                                     CGFloat textHeight;
                                     do {
                                         font = [UIFont systemFontOfSize:points];
                                         CGSize size = CGSizeMake(infoLabelRect.size.width, 100000);
                                         CGSize textSize = [text sizeWithFont:font constrainedToSize:size lineBreakMode: NSLineBreakByWordWrapping];
                                         textHeight = textSize.height;
                                         points -= 1;
                                     } while (textHeight > maxHeight);
                                     infoLabel.font = font;
                                     infoLabel.numberOfLines = 9;

                                     infoLabel.textColor = [UIColor whiteColor];
                                     infoLabel.textAlignment = NSTextAlignmentCenter;
                                     infoLabel.backgroundColor = [UIColor clearColor];
                                     infoLabel.shadowColor = [UIColor blackColor];
                                     infoLabel.shadowOffset = CGSizeMake(0, 1);

                                     [infoLabel sizeToFit];
                                     [contentView addSubview:infoLabel];


                                 } else {
                                     // Log details of our failure
                                     CGRect infoLabelRect = CGRectMake(10, 250, 260, 350);
                                     UILabel *infoLabel = [[UILabel alloc] initWithFrame:infoLabelRect];

                                     infoLabel.text = @"Connection error!";

                                 }
                             }];
4

1 に答える 1

1

コードの最初の部分にテキストへの割り当てが含まれていません

infoLabel.text = text; // or @"Some text" for testing

コードの最後の部分はUILabelを作成するだけで、サブビューとして追加しません

UILabel *infoLabel = [[UILabel alloc] initWithFrame:infoLabelRect];
infoLabel.text = @"Connection error!";
[contentView addSubview:infoLabel];
于 2012-12-03T17:37:33.457 に答える