最佳方法添加Static-TableView-Cells到UIViewcontroller? [英] Best approach to add Static-TableView-Cells to a UIViewcontroller?

查看:135
本文介绍了最佳方法添加Static-TableView-Cells到UIViewcontroller?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一个tableview-look-a-like-login到我的应用程序,但它似乎并不容易实现。我试图用更多的方法来完成我的目标,但我不知道哪个解决方案是最好的。

I want to add a tableview-look-a-like-login to my app, but it seems to be not that easy to implement. I tried to accomplish my goal using more then one approach, but i am not sure about which solution is the best.

例如,Dropbox和Facebook有这样的登录页面。

For example, Dropbox and Facebook have a login page like this.

这里有我的3种方法: / p>

Here are my 3 approaches :


  1. 我添加了2个UITextfield到我的视图(无边框) png在后面,看起来像一个tableviewcell。 (不是最好的方法,因为我想使用真实的tableview)

  1. I added 2 UITextfields to my View (no border) and placed a . png behind, which looks like a tableviewcell. ( Not the best approach cause i want to use real tableviews )

我添加了一个容器视图到我的ViewController放置了一个tableview静态表视图里面。这里的问题是,我不知道如何访问我的viewcontroller内的信息?

并使用动态单元格。将代理和数据源的出口连接到我的viewcontroller,并使用delegate和datasource方法初始化它们。这里的问题是,我不能在uiviewcontroller中使用静态表视图。

I added a tableview to my ViewController and used dynamic cells with it. Connected the outlets for delegate and datasource to my viewcontroller and initialized them with the delegate and datasource methods. The Problem here is, that i can not use static table views inside a uiviewcontroller.

任何更好的方法来解决这个问题?
我真的想知道如何以更优雅的方式做这件事。

Is there any better way of solving this problem ? I would really like to know how to do this in a more elegant way.

EDIT

一个ContainerViewController一个月前基本上解决了这个问题。
将一个嵌入到主控制器中之后,您可以通过 prepareForSegue 函数访问它,并为该特定控制器定义一个基于协议的接口,以便与嵌入式控制器进行交互。

A ContainerViewController basically solved this issue for me some month ago. After embedding one into the main controller you can access it through the prepareForSegue function and define a protocol-based interface for that specific controller to interact with the embedded controller.

推荐答案

我有一个想法如何解决这个问题。我认为这是一个干净的方式。

I have an idea how to solve this. I think it's a clean way to do so. You do not need storyboard for this controller.

使您的控制器子类UITableViewController像这样:

Make your controller subclass UITableViewController like so:

@interface YourViewController : UITableViewController

viewDidLoad你创建单元格的实例:

Then in your viewDidLoad you create the instances of the cells:

- (void) viewDidLoad {
    usernameCell = [YourTextFieldCell new];
    passwordCell = [YourTextFieldCell new];
}

YourTextFieldCell 当然你自己的子类UITableViewCell,可能是这样的:

The YourTextFieldCell is of course your own subclass of a UITableViewCell, which could be something like this:

@implementation YourTextFieldCell {
    UITextField textField;
}
- (id) init {
    self = [super init];
    if (self) {
        // Adjust the text's frame field to your liking
        textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 20)];
        [self addSubview:textField];
    }
}
// A getter method to access the textfield from the outside
- (UITextField *) textField {
    return textField;
}

@end

返回 YourViewController

- (NSInteger) tableView:(UITableView *) tv numberOfRowsInSection:(NSInteger) section {
    return 2;
}
- (UITableViewCell *) tableView:(UITableView *) tv cellForRowAtIndexPath:(NSIndexPath *) indexPath {
    if (indexPath.row == 0) {
        return usernameCell;
    } else if (indexPath.row == 1) {
        return passwordCell;
    }
    return nil;
}

你能得到我要去的地方吗?这是我认为你应该这样做!祝你好运!

Do you get where I am going with this? This is how I think you should do it! Good luck!

这篇关于最佳方法添加Static-TableView-Cells到UIViewcontroller?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆