iphone - 在标签上设置文本时出现 iOS 6 问题

标签 iphone ios objective-c uilabel

我的一些标签有问题。我制作了一个公共(public)方法,它从 TableView 中获取信息并在 3 个标签、 TextView 中显示此信息,并从网络加载图片。我在 TableView didSelectRowAtIndexPath 方法中设置了所有变量,但我在显示该信息时遇到了一些问题。我是这样做的: 在 TableView Controller 中,我调用了另一个方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.detailCharacterViewController = [[DetailCharacterViewController alloc] init];
    [self.detailCharacterViewController setupDetailViewControllerWithName:[self.arrayCharacters[indexPath.row] objectForKey:@"name"] andSurname:[self.arrayCharacters[indexPath.row] objectForKey:@"surname"] andKind:[self.arrayCharacters[indexPath.row] objectForKey:@"kind"] andDescription:[self.arrayCharacters[indexPath.row] objectForKey:@"description"] andImage:[self.arrayCharacters[indexPath.row] objectForKey:@"URLpic"]];
}

然后我实现了这个方法:

    - (void)setupDetailViewControllerWithName:(NSString*)name andSurname:(NSString *)surname andKind:(NSString*) kind andDescription:(NSString*)description andImage:(NSString*)url {
    NSLog(@"name = %@", name);
    self.labelName.text = name;
    self.labelSurname.text = surname;
    self.labelKind.text = kind;
    self.textDescription.text = description;

    NSURL *urlPic = [NSURL URLWithString:url];
    NSData *dataPic = [NSData dataWithContentsOfURL:urlPic];
    [self.imagePic setImage:[UIImage imageWithData:dataPic]];
}

如果我查看日志,我会看到正确的内容,但如果我查看 iPhone 或 iPhone 模拟器上的 GUI,它将保持空白。这段代码有什么问题? 谢谢你的建议。

@亚历克斯布伦德尔

#import <UIKit/UIKit.h>



@interface DetailCharacterViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *labelName;
@property (weak, nonatomic) IBOutlet UILabel *labelSurname;
@property (weak, nonatomic) IBOutlet UILabel *labelKind;
@property (weak, nonatomic) IBOutlet UIImageView *imagePic;
@property (weak, nonatomic) IBOutlet UITextView *textDescription;

- (void)setupDetailViewControllerWithName:(NSString*)name andSurname:(NSString *)surname andKind:(NSString*) kind andDescription:(NSString*)description andImage:(NSString*)url;

@end

最佳答案

问题是当您调用 setupDetailViewControllerWithName:... 时,您的 DetailCharacterViewController 的 View 尚未加载,因此(还)没有连接任何 socket 。通过 alloc-init 实例化 View Controller 不会自动加载它的 View 。

您可以通过在设置方法的开头调用 [self view] 来强制加载 View 。这是有效的,因为访问 view 属性将自动加载 View (如果之前未加载)。

或者,您可以将 namesurname 等设置为 View Controller 的 NSString 属性,并在 中设置相应的标签>viewDidLoad.

关于iphone - 在标签上设置文本时出现 iOS 6 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15987746/

相关文章:

objective-c - 使用对象容器中的 token 填充 NSTokenField

iphone - 具有 int 值的属性的值类型 Not Acceptable

objective-c - AVPlayer 不在文档目录 iOS 中播放 MP3 音频文件

iphone - 如何在 Objective C 中使用 NSData 创建 json 对象?

ios分析崩溃日志?

ios - 当我的应用程序首次启动时,iAd 拒绝在第一个屏幕上加载广告

iOS 13 上下文菜单 : how to simply dismiss menu by tapping on preview?

iphone - 使用 Target iOS 5.0 从 iOS SDK 6.1 加载 map 应用程序

iphone - 避免同时移动两个 View

iphone - 我可以在没有ios设备的情况下将应用程序提交到应用程序商店吗?