这段代码是如何工作的,重新设置 UITableViewController 的数据列表?
我有这段代码可以工作,但是我不太明白它是如何管理为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,
UITableViewController
将自身设置为其表视图的委托和数据源。由于您的类是 UITableViewController 的子类,因此它的作用相同。当然,这假设您已经实现了所有UITableViewDataSource
方法来实际使用tableData
数组(您在此处没有向我们展示)。By default,
UITableViewController
sets itself as the delegate and datasource of its table view. Since your class is a subclass ofUITableViewController
, it does the same. Of course, this assumes that you have implemented all theUITableViewDataSource
methods to actually use thetableData
array (which you aren't showing us here).