1

嗨,我遇到了 DetailViewController 不想设置 UILabel 插座的问题,这是一个 Master Detail 应用程序模板,当我按下一个单元格时会发生什么

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

    // here it accordingly sets the ObjectItem to my custom object.

    Torrent *object = _torrents[indexPath.row];
    [[segue destinationViewController] setObjectItem:object];
   }
}

这里是我在 DetailViewController viewDidLoad 中调用的方法

- (void)configureView
{
// Since i set the objectItem earlier it works, it set the outlets
if (self.objectItem) {

    theTitle.text = self.objectItem.MovieTitleClean;
    genre.text = self.objectItem.Genre;
    size.text = self.objectItem.Size;
    quality.text = self.objectItem.Quality;
    rating.text = self.objectItem.MovieRating;
    year.text = self.objectItem.MovieYear;
}

if (self.detailObject) {

    ShortDescription.lineBreakMode = NSLineBreakByWordWrapping;

    self.details = [_detailObject objectAtIndex:0];

    NSLog(@"Called"); // this is called meaning it should set the outlets but it doesn't...

resolution.text = self.details.Resolution;
framerate.text = self.details.FrameRate;
language.text = self.details.Language;
peersSeeds.text = [NSString stringWithFormat:@"%@/%@",self.details.TorrentPeers,self.details.TorrentSeeds];
downloaded.text = self.details.Downloaded;
ShortDescription.text = self.details.ShortDescription;

}

在 DetailViewController viewDidLoad 我调用 configureView 它将 UILabel 出口设置为我的自定义 objectItem 并且效果很好,但是当我从委托接收新的 detailObject 并根据该新 detailObject 设置其他 UILabel 时,似乎根本没有设置任何东西(注意)视图已经加载,一个 NSlog 显示我调用了 configureView,这意味着它假设设置了网点,我必须等待 15 秒,它会自动设置它们,有人知道为什么视图没有响应吗?它首先做到了。谢谢

编辑:这是 .h 文件

#import <UIKit/UIKit.h>

#import "TorrentDetail.h"

#import "YifyAPI.h"
#import "Torrent.h"

@interface DetailViewController : UIViewController <YifyAPIDelegate> {

IBOutlet UILabel *theTitle;
IBOutlet UILabel *genre;
IBOutlet UILabel *size;
IBOutlet UILabel *quality;
IBOutlet UILabel *rating;
IBOutlet UILabel *year;

IBOutlet UILabel *resolution;
IBOutlet UILabel *framerate;
IBOutlet UILabel *language;
IBOutlet UILabel *peersSeeds;
IBOutlet UILabel *downloaded;

IBOutlet UILabel *ShortDescription;

IBOutlet UIImageView *LargeImageCover;
}

@property (strong, nonatomic) Torrent *objectItem;

@property (strong, nonatomic) TorrentDetail *detailObject;

@end
4

2 回答 2

0

要在从故事板加载的视图控制器中配置属性,不要依赖 viewDidLoad: 来初始化属性。文档中的此处此处都说要覆盖awakeFromNib以进行配置。

// In your Detail View Controller
- (void) awakeFromNib
{
    [self configureView];
    // Do any other configuration here
}
于 2013-10-30T01:49:39.273 回答
0

这是正常的,因为当你加载控制器时,对象并没有被设置,然后你加载它来解决这个问题你可以这样做,在你的 detailControll 中,你像这样实现你的对象的设置器:

-(void)setObjectItem:(Torrent *)object{

   if(_objectItem != object){
       _objectItem = object;
   }

    theTitle.text = self.objectItem.MovieTitleClean;
     genre.text = self.objectItem.Genre;
     size.text = self.objectItem.Size;
     quality.text = self.objectItem.Quality;
     rating.text = self.objectItem.MovieRating;
     year.text = self.objectItem.MovieYear;

}

-(void)setDetailObject:(NSArray *) detailObject{

   if(_detailObject != detailObject){
       _detailObject = detailObject;
   }

    ShortDescription.lineBreakMode = NSLineBreakByWordWrapping;

    self.details = [_detailObject objectAtIndex:0];

    NSLog(@"Called"); // this is called meaning it should set the outlets but it doesn't...

     resolution.text = self.details.Resolution;
     framerate.text = self.details.FrameRate;
     language.text = self.details.Language;
     peersSeeds.text = [NSString stringWithFormat:@"%@/%@",self.details.TorrentPeers,self.details.TorrentSeeds];
     downloaded.text = self.details.Downloaded;
     ShortDescription.text = self.details.ShortDescription;

    }
于 2013-10-30T00:51:58.530 回答