iOS 5 中委托模式呈现视图

发布于 12-13 08:47 字数 1197 浏览 0 评论 0原文

我似乎无法在网上找到这个。我的一个视图中有一个添加按钮,并且我已将其连接到名为 addIBAction 方法。在我的故事板中,我创建了一个视图,其中设置了所有表单。我也在故事板中为该视图分配了一个类。该类称为 AddItemViewController

我试图以模态方式呈现此视图,然后将委托设置为调用 AddItemViewController 的视图。然而,我得到的只是显示一个空的 UITableViewController 。这是我尝试使用的代码:

- (IBAction)add {
    AddItemViewController *addItem = [[AddItemViewController alloc] init];
    addItem.delegate = self;
    [self presentModalViewController:addItem animated:YES];
}

我缺少什么吗?为什么它只显示一个空表,而不显示我在情节提要中设置的视图控制器?

以下是 AddItemViewController 中的代码:

@interface AddItemViewController : UITableViewController <UITextFieldDelegate> {
}

@property (strong, nonatomic) IBOutlet UITextField *note;

- (void)save:(id)sender;
- (void)cancel:(id)sender;
@end


@implementation AddItemViewController
    - (void)viewDidLoad {

    }

    - (IBAction)cancel:(id)sender {
        [self dismissViewControllerAnimated:YES completion:nil];
    }

    - (IBAction)save:(id)sender {
        DbHandler *db = [[DbHandler alloc] init];
        [db executeUpdate:self.note];

        [self dismissViewControllerAnimated:YES completion:nil];
    }
@end

I cannot seem to find this anywhere online. I have an add button in one of my views and I have hooked it up to an IBAction method called add. In my storyboard, I have created a view that has a form all set up on it. I have assigned a class to that view in the storyboard as well. That class is called AddItemViewController.

I am trying to present this view modally and then set the delegate to the view that called the AddItemViewController. However, all I get is an empty UITableViewController that shows up. Here is my code that I'm trying to use:

- (IBAction)add {
    AddItemViewController *addItem = [[AddItemViewController alloc] init];
    addItem.delegate = self;
    [self presentModalViewController:addItem animated:YES];
}

Is there anything I'm missing? Why does it just show an empty table and not the view controller that I set up in the storyboard?

Here is the code from the AddItemViewController:

@interface AddItemViewController : UITableViewController <UITextFieldDelegate> {
}

@property (strong, nonatomic) IBOutlet UITextField *note;

- (void)save:(id)sender;
- (void)cancel:(id)sender;
@end


@implementation AddItemViewController
    - (void)viewDidLoad {

    }

    - (IBAction)cancel:(id)sender {
        [self dismissViewControllerAnimated:YES completion:nil];
    }

    - (IBAction)save:(id)sender {
        DbHandler *db = [[DbHandler alloc] init];
        [db executeUpdate:self.note];

        [self dismissViewControllerAnimated:YES completion:nil];
    }
@end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧时浪漫2024-12-20 08:47:11

好吧,AddItemViewController 继承自 UITableViewController,而不是 UIViewController,因此显示 UITableViewController 是有意义的。

您应该像这样启动 AddItemViewController

AddItemViewController *addItem = [[AddItemViewController alloc] initWithNibName:@"AddItemViewController"];

Well, AddItemViewController inherits from UITableViewController, not UIViewController, so it makes sense that a UITableViewController is showing up.

You should initiate the AddItemViewController like this:

AddItemViewController *addItem = [[AddItemViewController alloc] initWithNibName:@"AddItemViewController"];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文