我是Objective-C的新手,需要幫助!UIPageControl with UIView with button
我正在關注可以在網上找到的示例「PageControl」。我在NIB的視圖中添加了一個按鈕,並在下面找到了一個實現的操作。
這裏被顯示在頁面控制我的視圖控制器定義:
//ContactCardViewController.h @interface ContactCardViewController : UIViewController { int pageNumber; NSMutableString *s; } //ContactCardViewController.m implementation - (id)initWithPageNumber:(int)page { if (self = [super initWithNibName:@"ContactCardViewController" bundle:nil]) { s = [[NSString alloc] initWithFormat:@"page: %d", page]; } return self; } - (id)initWithString:(NSDictionary *)_s { if (self = [super initWithNibName:@"ContactCardViewController" bundle:nil]) { NSMutableString *t = [[NSMutableString alloc] initWithString:_s]; s = t; } return self; } -(IBAction)callOrAddToContacts:(id)sender { jobtitleLabel.text = s; } //AppDelegate.m //in delegate that loads the scroll view with the view for the current page: - (void)loadScrollViewWithPage:(int)page { //init the view this way the page: and the correct page number is displayed controller = [[ContactCardViewController alloc] initWithPageNumber:page ]; //init the view this way, the value of the first person is always displayed controller = [[ContactCardViewController alloc] initWithString:[[self.allNames objectAtIndex:page] objectForKey:@"firstname"]]; }
請幫助我理解爲什麼當視圖與initWithString創建,然後通過按鈕操作只對價值訪問列表中的第一個人總是返回。當我使用initWithPageNumber初始化視圖時,s具有正確的值頁面:X.
非常感謝!複製/粘貼錯誤。用
存在同樣的問題。嘗試讀取s時,動作中的代碼始終讀取列表中的第一個值,而不管控件當前處於哪個頁面 – radiofrequency 2009-08-14 18:46:39