2013-12-15 70 views
1

我想加載另一個視圖,當我點擊我的UITableCell視圖之一,但沒有任何在xib文件(與該視圖相關)的東西正在顯示。物品在視圖中沒有出現在加載

這是我如何初始化的觀點(在生成tableView控制器):

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     self.title = @"Cards"; 
     self.detailController = [[BasicCardViewController alloc] initWithNibName: @"CardView" bundle:nil]; 
    } 
    return self; 
} 

這是我處理的選擇:

- (void)tableView:(UITableView *) tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSDictionary *component = self.resultsTuples[indexPath.row]; 

    [AJAXUtils getAsyncJsonWithUrl:(NSURL *)[NSURL URLWithString:someUrl] callback:^(NSDictionary *returnjson) { 
     if (returnjson != nil) { 
      NSString *userPageLink = returnjson[@"Node"][@"SessionInfo"][@"PostingAs"][@"Key"]; 
      self.detailController.userPageLink = userPageLink; 
      self.detailController.nodePage = returnjson[@"Node"][@"Key"]; 

      NSString *selectedCard = component[@"$element"][@"Title"]; 
      [self.detailController setDescription:component[@"element"][@"ContactCard"][@"Description"]]; 
      [self.detailController setPageTitle:selectedCard]; 
      self.detailController.title = selectedCard; 

      NSString* rating = component[@"$element"][@"Summary"][@"AverageRating"]; 
      self.detailController.rating =(NSInteger)rating; 
      [self.navigationController pushViewController:self.detailController animated:YES]; 
     } 
    }]; 
} 

這是我BasicCardView code -

@implementation BasicCardViewController 
@synthesize userPageLink = _userPageLink; 
@synthesize nodePage = _nodePage; 

- (void)viewDidLoad { 
    _trendingImageView.image = [UIImage imageNamed:@"trending.png"]; 
} 

- (UILabel *)label { 
    return (id)self.view; 
} 

- (void)loadView { 
    self.rateView = [[RateView alloc] init]; 
} 

- (void)setDescription:(NSString *)description { 
    _description = description; 
    _descriptionView.text = description; 
} 

- (void)setPageScore:(NSString *)pageScore { 
    _pageScore = pageScore; 
    _pageScoreLabel.text = pageScore; 
} 

- (void)setRestaurantImage:(UIImage *)restaurantImage { 
    _restaurantImage.image = restaurantImage; 
} 

- (void)setPageTitle:(NSString *)title { 
    _pageTitle = title; 
} 

-(void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear: animated]; 

    self.rateView.notSelectedStar =[UIImage imageNamed:@"kermit_empty.png"]; 
    self.rateView.halfSelectedStar = [UIImage imageNamed:@"kermi_half.png"]; 
    self.rateView.fullSelectedStar = [UIImage imageNamed:@"kermit_full.png"]; 
    self.rateView.rating = self.rating; 
    self.rateView.editable = YES; 
    self.rateView.maxRating = 5; 
    self.rateView.delegate = self; 
    _pageTitleLabel.text = _pageTitle; 
} 

單擊單元格時爲什麼不顯示?
但是,如果我在viewDidLoad中做self.view = rateView,rateView出現。

回答

0

視圖控制器在請求其視圖屬性時調用loadView方法,但當前爲零。此方法加載或創建視圖並將其分配給視圖屬性。它看起來好像你的self.view是零,在loadView方法中,你已經創建了self.rateView,但沒有將其分配給self.view以使其可見。

+0

對..但我的觀點不只是比率視圖 - 還有其他一些東西。費率視圖是它的一個組件,我的xib文件也有一堆標籤和東西。我在其他地方調用了initWithNibName,所以self.detailController應該是一個視圖控制器,該視圖控制器使用具有費率視圖和標籤以及其他東西的xib文件初始化。 – praks5432

+0

視圖控制器中是否顯示了其他視圖? – ldindu

+0

好吧,如果我做self.view = oneOfMyLabels然後標籤顯示 – praks5432

0

也許getAsyncJsonWithUrl塊調出的主線程嘗試的,打電話給mainQueuepushViewController如下:

[[NSOperationQueue mainQueue] addOperationWithBlock:^{ 
    [self.navigationController pushViewController:self.detailController animated:YES];  
}]; 
+0

我不認爲這是問題 - 當我做自我時.view = viewDidLoad中的self.rateView - 出現rateView。 – praks5432

0

它有時可能會有所幫助。
_detailController = [[BasicCardViewController alloc] initWithNibName:@「CardView」bundle:nil];