DetailViewController无法设置插座?

时间:2013-10-30 00:33:47

标签: ios objective-c cocoa-touch master-detail

嗨我有一个问题,其中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

2 个答案:

答案 0 :(得分:0)

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

-(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;

    }

答案 1 :(得分:0)

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

// In your Detail View Controller
- (void) awakeFromNib
{
    [self configureView];
    // Do any other configuration here
}