我有一些标签的问题。我创建了一个公共方法,它从表格视图中获取信息,并在 3 个标签、一个文本视图中显示此信息,并从网络加载图片。我在表视图 didSelectRowAtIndexPath 方法中设置了所有变量,但是在显示该信息时遇到了一些问题。我这样做了:在表视图控制器中,我调用了另一种方法:
- (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