这段代码是如何工作的,重新设置 UITableViewController 的数据列表?

发布于 2024-10-19 12:34:01 字数 1673 浏览 0 评论 0原文

我有这段代码可以工作,但是我不太明白它是如何管理为 UITableViewController 设置数据源的?这是否必须通过 Interface Builder 设置以某种方式发生?

也就是说,如果您看到“tableData = [[NSMutableArray alloc] initWithObjects: etc””这一行,并且事实上我没有看到这里的“tableData”实例变量实际上被分配为 UITableView 的数据... PS(编辑)那么

@interface RootViewController : UITableViewController <NewItemControllerDelegate> {  

    NSMutableArray *tableData;
}
@end


@implementation RootViewController
- (void)viewDidLoad {
  [super viewDidLoad];
  tableData = [[NSMutableArray alloc] initWithObjects:@"My Standard View", @"A Different View", nil];   // <== HOW IS THIS MANAGING TO SET THE VIEW WITH THE DATA
}

并供参考

@interface myProjectAppDelegate : NSObject <UIApplicationDelegate> {

    UIWindow *window;
    UINavigationController *navigationController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@end


@implementation myProjectAppDelegate
@synthesize window;
@synthesize navigationController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.

    // Add the navigation controller's view to the window and display.
    [self.window addSubview:navigationController.view];
    [self.window makeKeyAndVisible];

    return YES;
}

我不太明白的是我在 RootViewController 头文件中声明的“NSMutableArray *tableData”变量与实际 UITableViewController 的数据源之间的链接? UITableViewController 中是否有一个默认的“tableData”,也许这就是我真正设置的东西,所以我并没有真正将新的 NSMutableArray 分配给我创建的变量,而是另一个变量? (希望这是有道理的)>

I have this code working, however I don't quite understand how it is managing to set the data source for the UITableViewController? Would this have to be occurring via Interface Builder settings somehow?

That is if you see the line "tableData = [[NSMutableArray alloc] initWithObjects: etc", and the fact that I don't see where my "tableData" instance variable here is actually assigned to be the data for the UITableView....

@interface RootViewController : UITableViewController <NewItemControllerDelegate> {  

    NSMutableArray *tableData;
}
@end


@implementation RootViewController
- (void)viewDidLoad {
  [super viewDidLoad];
  tableData = [[NSMutableArray alloc] initWithObjects:@"My Standard View", @"A Different View", nil];   // <== HOW IS THIS MANAGING TO SET THE VIEW WITH THE DATA
}

and for reference

@interface myProjectAppDelegate : NSObject <UIApplicationDelegate> {

    UIWindow *window;
    UINavigationController *navigationController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@end


@implementation myProjectAppDelegate
@synthesize window;
@synthesize navigationController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.

    // Add the navigation controller's view to the window and display.
    [self.window addSubview:navigationController.view];
    [self.window makeKeyAndVisible];

    return YES;
}

PS (edit) So what I can't quite understand is the linkage between my "NSMutableArray *tableData" variable I declared in the RootViewController header file, and the actual UITableViewController's datasource so to speak? Is there a default "tableData" in a UITableViewController perhaps that is what I'm really setting or something, so I'm not really allocating new NSMutableArray to my variable I created but another one? (hope this makes sense)>

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

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

发布评论

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

评论(1

仅此而已 2024-10-26 12:34:01

默认情况下,UITableViewController 将自身设置为其表视图的委托和数据源。由于您的类是 UITableViewController 的子类,因此它的作用相同。当然,这假设您已经实现了所有 UITableViewDataSource 方法来实际使用 tableData 数组(您在此处没有向我们展示)。

By default, UITableViewController sets itself as the delegate and datasource of its table view. Since your class is a subclass of UITableViewController, it does the same. Of course, this assumes that you have implemented all the UITableViewDataSource methods to actually use the tableData array (which you aren't showing us here).

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