簡體   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