这是我的第一篇关于IOS的文章,可能有些不对的地方,希望大家指正。
步骤:
一:
1.建立一个项目,其ViewController的类型是UITableViewController,设置其identifier——MyTextCell;(点击viewcontroller的控制器后 点击上面的标题栏Editor中的embed in中的Navigation)
2.添加一个新的controller,MyPicturesViewController继承UITableViewController,设置其identifier——MyPicCell;
3.建立segue,从ViewController的控制器按住ctrl添加segue到MyPicturesViewController,选择show,其segue的identifier是ShowPic
初步的view视图工作完成了。
第二部分就是代码的,
二:
1.为ViewController添加数据源,创建newGroup——ModelClass,在ModelClass中创建cocoa Touch class的NSObject类ViewControllerInfo。
2.在ViewControllerInfo中初始化一些信息
ViewControllerInfo.h文件中:
#import<Foundation/Foundation.h>
@interface ViewControllerInfo :NSObject
@property (nonatomic,strong)NSArray *cellInfo;
@end
#import "ViewControllerInfo.h"
@implementation ViewControllerInfo
- (id)init{
if (self = [superinit]) {
[selfinitCellInfo];
}
return self;
}
- (void)initCellInfo{
_cellInfo = [[NSArrayalloc]initWithObjects:@"内容一",@"内容二",@"内容三",nil];
}
@end
ViewController.m文件中:
3.给ViewController中的Cell初始化内容。
#import "ViewController.h"
#import "ViewControllerInfo.h"
#import "MyPicturesViewController.h"
@interfaceViewController ()
@property (nonatomic,strong)ViewControllerInfo *viewInfo;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
[selfconfigureViewInfo];
}
//加载数据。
- (void)configureViewInfo{
_viewInfo = [[ViewControllerInfoalloc]init];
}
//行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
returnself.viewInfo.cellInfo.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)in