2011-07-29 51 views
0

我正在開發iPad應用程序,這是我第一次將彈出視圖良好使用。我將popover視圖用作帶有類別的菜單,並且只有1個屏幕帶有視頻。當用戶選擇一個類別時,'FeaturedViewController'必須用新的playlistId重新加載視圖。如何從委託中獲取價值並重新加載視圖

當用戶選擇一個類別,這很容易做到:double playlistId = [[playlists.items objectAtIndex:indexPath.row] playlistId];

但我怎麼拿到playlistId在我FeaturedViewController並重新加載看法?

+0

你有沒有在委託文件中聲明你的播放列表變量? – Maulik

+0

是的,我已經綜合了它和一切;但是甚至不會把ID放回NSLog。 – MaikelS

+0

給一些更多的代碼。你如何試圖獲得一個ID? – Maulik

回答

0

看:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
// load new playlist 
BCPlaylist *playlist = (BCPlaylist *) [playlists.items objectAtIndex:indexPath.row]; 
NSNumber *key = [NSNumber numberWithDouble:playlist.playlistId]; 
NSLog(@"Key: %@", key); 
FeaturedViewController *nextView = [[FeaturedViewController alloc] initWithNibName:nil bundle:nil]; 
nextView.PLID = key; 
[self.navigationController pushViewController:nextView animated:YES]; 
[nextView release]; 
} 

重點NSlogs正確的,但我不得到nextView.PLID在FeaturedViewController的迴應都沒有。

+0

哦,順便說一下,自我presentModalViewController也不會做這項工作。這當然只是描繪了主要觀點。 – MaikelS

0
在FeaturedViewController.m

- (void)viewDidLoad 
{ 
    //create reference of your delegate 
    YourAppDelegate rootApp = (YourAppDelegate *)[[UIApplication sharedApplication]delegate]; 

    double playlistId = [[[[rootApp playlists] items] objectAtIndex:indexPath.row] playlistId ]; 
    [super viewDidLoad]; 
} 

EDITED

或者你可以在FeaturedViewController定義屬性,並在此VC像賦值:

FeaturedViewController nextView = [[FeaturedViewController alloc] initWithNibName:@"FeaturedViewController" bundle:nil]; 
//below lineset the value of property and you can pass value to nextView 
    nextView.playlistId = [[playlists.items objectAtIndex:indexPath.row] playlistId]; ; 
    [self.navigationController pushViewController:nextView animated:YES]; 

希望它讓你想法訪問變量的代表

+0

將nextView定義爲什麼? – MaikelS

+0

它的一個FeaturedViewController的對象檢查更新答案! – Maulik

+0

當我嘗試NSLog playlistId的readwrite double時,輸出爲空。我認爲它不會推送到FeaturedViewController並重新加載。你是什​​麼意思的物體btw?雙重不是一個對象? – MaikelS

相關問題