以前都是使用IB,今天在CC上看了使用代码添加控件,我就试试了,成功了。保存步骤和代码了。
1.创建一个View-Based Application,然后把里面的xib文件全部删掉。(我创建的工程为IP_codeTest)
2.打开IP_codeTest-info.plist文件,删除最下面的一行。Main nib file base name
3.打开main函数,把int retVal = UIApplicationMain(argc, argv, nil, nil)修改为:
int retVal = UIApplicationMain(argc, argv, nil, @"IP_codeTestAppDelegate");
4.打开IP_codeTestAppDelegate.m文件,修改成如下内容:
5.打开IP_codeTestViewController.h,修改代码:
#import <UIKit/UIKit.h>
@interface IP_codeTestViewController : UIViewController
<UITableViewDelegate, UITableViewDataSource>
{
}
@property (nonatomic, retain) UITableView *table;
@property (nonatomic, retain) NSArray *array;
@end
6.打开IP_codeTestViewController.m,添加如下代码:
-(void)viewDidLoad
{
}
- (NSInteger)numberOfSectionsInTableV
{
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
}
我的实验仅仅是使用代码添加一个tableView,添加其他东西原理应该一样。以后继续摸索!!