【问题标题】:UIPageControl with UIView with buttonUIPageControl 与 UIView 与按钮
【发布时间】:2010-11-19 12:23:57
【问题描述】:

我是 Objective-C 的新手,需要帮助!

我正在关注可以在网上找到的示例“PageControl”。我在 NIB 中的视图中添加了一个按钮,并连接了一个操作,其实现如下所示。

这是我在页面控件中显示的视图控制器的定义:

//ContactCardViewController.h @interface ContactCardViewController : UIViewController { 整数页码; NSMutableString *s; } //ContactCardViewController.m 实现 - (id)initWithPageNumber:(int)page { if (self = [super initWithNibName:@"ContactCardViewController" bundle:nil]) { s = [[NSString alloc] initWithFormat:@"page: %d", page]; } 回归自我; } - (id)initWithString:(NSDictionary *)_s { if (self = [super initWithNibName:@"ContactCardViewController" bundle:nil]) { NSMutableString *t = [[NSMutableString alloc] initWithString:_s]; s = t; } 回归自我; } -(IBAction)callOrAddToContacts:(id)sender { jobtitleLabel.text = s; } //AppDelegate.m //在使用当前页面视图加载滚动视图的委托中: - (void)loadScrollViewWithPage:(int)page { //以这种方式初始化视图页面:并显示正确的页码 控制器 = [[ContactCardViewController alloc] initWithPageNumber:page ]; //这样初始化视图,第一人称的值总是显示出来的 控制器 = [[ContactCardViewController alloc] initWithString:[[self.allNames objectAtIndex:page] objectForKey:@"firstname"]]; }

请帮助我理解为什么当使用 initWithString 创建视图然后通过按钮操作访问时,总是返回列表中第一个人的值。当我使用 initWithPageNumber s 初始化视图时,页面具有正确的值:X。

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:

    在 InitWithString 代码中,您传递的是字典,而不是字符串。

    - (id)initWithString:(NSDictionary *)_s {
        if (self = [super initWithNibName:@"ContactCardViewController" bundle:nil]) {
            NSMutableString *t = [[NSMutableString alloc] initWithString:_s];
            s = t;
        }
        return self;
    }

    您可能希望将其更改为 NSString,或将 NSMutableString... 更改为 NSDictionary 的实例。一个或另一个。

    【讨论】:

    • 好的,谢谢!复制/粘贴错误。使用
       - (id)initWithString:(NSMutableString *)_s { 
      存在同样的问题。尝试读取 s 时操作中的代码始终读取列表中的第一个值,而不管控件当前位于哪个页面
    【解决方案2】:

    发现问题出在 plist 文件中。代码很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-12
      • 2013-05-22
      • 2012-11-01
      相关资源
      最近更新 更多