2010-01-04 101 views
1

我想從ViewController傳遞一個數字給TweetViewController。一切工作正常,我NSUInteger做到了財產(randomNumber和tweetNumber):問題:無法將NSUInteger從一個ViewController傳遞到另一個ViewController

TweetViewController *Second = [[TweetViewController alloc] initWithNibName:nil bundle:nil]; 
    Second.tweetNumber = randomNumber; 
    Second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
    [self presentModalViewController:Second animated:YES]; 
    [Second release]; 

我現在已經改變了我的代碼,因爲我不希望只有我TweetViewVontroller被加載。我想要在Tweet-和InfoViewController之間進行主屏幕滑動。我使用一個SwitchViewController,它將加載而不是TweetViewController。該SwitchViewController看起來是這樣的(窗口1/2的UIViewController):

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,320,460)]; 
UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0,0,640,460)]; 

self.window1 = [TweetViewController alloc]; 
self.window2 = [InfoViewController alloc]; 


[contentView addSubview:self.window1.view]; 

CGRect f = self.window2.view.frame; 
f.origin.x = 320; 
self.window2.view.frame = f; 

[contentView addSubview:self.window2.view]; 


[scrollView addSubview:contentView]; 
scrollView.contentSize = contentView.frame.size; 

scrollView.pagingEnabled = YES; 

self.view = scrollView; 

[contentView release]; 
[scrollView release]; 

現在我不能從FirstViewController到TweetViewController經過數。任何想法,如何解決問題?

回答

1
window1.tweetNumber = randomNumber; 

如果你想在每次滾動scrollview時更新它,你可能需要查看UIScrollViewDelegate協議。特別是scrollViewWillBeginDragging:

+0

window1.tweetNumber不起作用,因爲他說「請求會員」tweetnumber「不是結構或聯合」 – Flocked 2010-01-04 14:00:11

+0

奇怪,嘗試'[window1 setTweetNumber:randomNumber];'。當你在這裏時,你不應該先啓動兩個控制器嗎? – Rengers 2010-01-04 14:07:26

+0

謝謝,這工作! :) 我5min前更新了我的代碼並初始化控制器;) – Flocked 2010-01-04 14:11:05

相關問題