繁体   English   中英

DetailViewController无法设置插座?

[英]DetailViewController can't set outlets?

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

这是正常的,因为在加载控制器时未设置该对象,而是在加载该对象以解决此问题时可以这样做,在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;

    }

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM