带有UIView按钮的UIPageControl
我是Objective-C的新手,需要帮助!
我正在关注可以在网上找到的示例“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有正确的值Page:X.
在InitWithString代码中,传递的是Dictionary,而不是字符串。
- (id)initWithString:(NSDictionary *)_s {
if (self = [super initWithNibName:@"ContactCardViewController" bundle:nil]) {
NSMutableString *t = [[NSMutableString alloc] initWithString:_s];
s = t;
}
return self;
}
您可能希望将其更改为NSString,或将NSMutableString ...更改为NSDictionary的实例。 非此即彼。
发现问题出在plist文件中。 代码很好。
链接地址: http://www.djcxy.com/p/78231.html上一篇: UIPageControl with UIView with button
下一篇: How to load a UIView using a nib file created with Interface Builder