我有这个代码工作,但是我不太明白它是如何管理为 UITableViewController 设置数据源的?这是否必须通过 Interface Builder 设置以某种方式发生?
也就是说,如果您看到“tableData = [[NSMutableArray alloc] initWithObjects: etc””这一行,并且事实上我没有看到这里的“tableData”实例变量实际上被分配为 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
}
供引用
@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(编辑)所以我不太明白的是我在 RootViewController 头文件中声明的“NSMutableArray *tableData”变量与实际 UITableViewController 的数据源之间的链接? UITableViewController 中是否有一个默认的“tableData”,也许这就是我真正设置的东西,所以我并没有真正将新的 NSMutableArray 分配给我创建的变量,而是另一个变量? (希望这是有道理的)>
最佳答案
默认情况下,UITableViewController
将自身设置为其 TableView 的委托(delegate)和数据源。由于您的类是 UITableViewController 的子类,因此它的作用相同。当然,这假设您已经实现了所有 UITableViewDataSource
方法来实际使用 tableData
数组(您没有在此处向我们展示)。
关于iphone - 这段代码如何工作,重新设置 UITableViewController 数据列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5129697/