iOS 定制手机通讯录(1)

我要写第一个自己写的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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值