我要写第一个自己写的iOS APP啦,都闪开闪开!
仍照着Homepwner扒,建个NMTel,先解决Empty Application模版的问题
把 Main.storyboard 和 LaunchScreen.xib 删掉,
把 Info.plist 里边的 Launch screen interface file base name 和 Main storyboard file base name两项删掉,
最后在AppDelegate的第一个方法里面添加代码:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
建UITableViewController类的BNRItemsViewController,在BNRItemsViewController实现初始化方法
- (instancetype)init
{
self = [super initWithStyle:UITableViewStylePlain];
return self;
}
- (instancetype)initWithStyle:(UITableViewStyle)style
{
return [self init];
}
在AppDelegate.m里边导入
#import “BNRItemsViewController.h”
再在第一个方法里加入
BNRItemsViewController *itemsViewController = [[BNRItemsViewController alloc] init];
self.window.rootViewController = itemsViewController;
这时运行应用,BNRItemsViewController中的view方法会调用loadView方法,得到一个空的UITableView对象。
下面写生成数据的对象,建立BNRItem,有4个实例变量,分别保存姓名、手机号、分机号、邮箱,一个实例方法initWithItemName用来传消息生成数据。
实现initWithItemName,并覆盖description方法。
BNRItem.h
#import
@interface BNRItem : NSObject
{
NSString *_NMTelContactName;
NSString *_NMTelCellPhone;
NSString *_NMTelLandLine;
NSString *_NMTelContactEmail;
}
- (instancetype)initWithItemName:(NSString *)ContactName
NMTelCellPhone:(NSString *)CellPhone
NMTelLandLine:(NSString *)LandLine
NMTelContactEmail:(NSString *)ContactEmail;
@property (nonatomic, copy) NSString *NMTelContactName;
@property (nonatomic, copy) NSString *NMTelCellPhone;
@property (nonatomic, copy) NSString *NMTelLandLine;
@property (nonatomic, copy) NSString *NMTelContactEmail;
@end
BNRItem.m
#import “BNRItem.h”
@implementation BNRItem
- (NSString *)description
{
NSString *descriptionString =
[[NSString alloc] initWithFormat:@”%@ %@ %@ %@”,
self.NMTelContactName,
self.NMTelCellPhone,
self.NMTelLandLine,
self.NMTelContactEmail];
return descriptionString;
}
- (instancetype)initWithItemName:(NSString *)ContactName
NMTelCellPhone:(NSString *)CellPhone
NMTelLandLine:(NSString *)LandLine
NMTelContactEmail:(NSString *)ContactEmail
{
self = [super init];
if (self) {
_NMTelContactName = ContactName;
_NMTelCellPhone = CellPhone;
_NMTelLandLine = LandLine;
_NMTelContactEmail = ContactEmail;
}
return self;
}
@end
测试main.m,initWithItemName是有效的
#import
#import “BNRItem.h”
int main(int argc, const char * argv[]) {
@autoreleasepool {
BNRItem *item = [[BNRItem alloc] init];
item.NMTelContactName = @”郑华恩”;
item.NMTelCellPhone = @”18801767597″;
item.NMTelLandLine = @”873″;
item.NMTelContactEmail = @”huaen@niumag.com”;
NSLog(@”%@”, item);
item = nil;
BNRItem *itemWithName = [[BNRItem alloc] initWithItemName:@”郑华恩”
NMTelCellPhone:@”18801767597″
NMTelLandLine:@”873″
NMTelContactEmail:@”huaen@niumag.com”];
NSLog(@”%@”, itemWithName);
}
return 0;
}
把BNRItem.h和BNRItem.m文件加入到NMTel