OGeek|极客世界-中国程序员成长平台

标题: iphone - 这段代码如何工作,重置 UITableViewController 数据列表? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:59
标题: iphone - 这段代码如何工作,重置 UITableViewController 数据列表?

我有这段代码工作,但我不太明白它是如何管理为 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)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)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 分配给我创建的变量,而是另一个? (希望这是有道理的)>



Best Answer-推荐答案


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

关于iphone - 这段代码如何工作,重置 UITableViewController 数据列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5129697/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4