【问题标题】:three tables in the same window, iPad三张桌子在同一个窗口,iPad
【发布时间】:2010-12-15 06:06:43
【问题描述】:

您好,我正在开发一个应用程序,在横向模式下, 我需要在同一个窗口中显示 3 个表格, 如何做到这一点? 作为我的视图控制器,我有一张桌子>

@interface ChoiceViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{ 
    NSMutableArray *array;
}

但是如何在 xib 中连接新表?如何调用其他委托、数据源、 用于创建新表的 Uitableview?

谢谢!

【问题讨论】:

    标签: cocoa-touch ipad uitableview uikit uiviewcontroller


    【解决方案1】:

    在视图控制器的界面中添加 IBOutlets:

    @interface ChoiceViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
    {
        UITableView *table1;
        UITableView *table2;
        UITableView *table3;
        NSMutableArray *array;
    }
    
    @property(nonatomic,retain) IBOutlet UITableView *table1;
    @property(nonatomic,retain) IBOutlet UITableView *table2;
    @property(nonatomic,retain) IBOutlet UITableView *table3;
    @end
    

    在 Interface Builder 中将出口连接到视图控制器,可选择将表视图的委托/数据源出口连接回视图控制器。然后将以下内容添加到实现中。

    @implementation ChoiceViewController
    
    @synthesize table1, table2, table3;
    
    - (void) dealloc
    {
        self.table1 = nil;
        self.table2 = nil;
        self.table3 = nil;
        // Most likely, [array release];
        [super dealloc];
    }
    
    @end
    

    在您的 UITableViewDelegate/UITableViewDataSource 方法中测试哪个表视图请求数据并返回适当的数据。

    或者,您可以设置多个数据源,每个数据源负责一个表格视图,但这取决于您应用的设计。

    【讨论】:

    • 你好,谢谢,我试过这个方法,但出现了一些错误,这个方法可以在每个表中放置不同的数据吗? tnx
    • 是的。如果视图控制器对要在表中显示的数据具有逻辑访问权限,那么这是有道理的。否则,拥有不同的数据源/委托可能会更好。你看到什么样的错误?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 2012-05-23
    • 1970-01-01
    • 2014-07-13
    • 1970-01-01
    相关资源
    最近更新 更多