我是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