今天居然会迷恋上了塔防游戏,晕,打了一天,终于想到还有要学习的东西,坚持,还是真的不容易啊!
其实这个这个stroyboard只是让我们更加方便的去切换自己页面。不过原理和以前的是有很大的区别。
创建一个新的storyboard项目呢。
选择Single View Application 接着next
这里要选择Use Storyboard哦!这样就创建好了,因为这是Apple已经为我们做好的。
接下来就是动态原型单元。
实际上就是创建一个UIViewController subClass 然后绑定到相应的UIViewController上。我是这样理解的。
这样才算是选中了表视图控制器,在身份检查器中将class 修改为BIDTaskListController。
在Prototype Cells的属性Identifier 设为plainCell。将label拖入到其中 并将Tag值设为1。选中表视图单元,可以从dock中比较容易好选,Edit--Duplicate 就复制了一个新单元。
选中新单元,修改Identifier修改为attentionCell。将标签颜色修改为红色,字体修改为System Bold。
在#import "BIDTaskListController.h"
文件中添加
@interface BIDTaskListController()
@property(strong,nonatomic) NSArray *tasks;
@end
在ViewdidLoad的时候添加数据
self.tasks=[NSArray arrayWithObjects:@"Walk the dog",@"URGENT:Buy milk",@"Clean hidden lair",@"Invent miniature dolphins",
@"Find new henchmen",@"Get revenge on do-gooder heroes",@"URGENT:Fold laundry",@"Hold entire world hostage",@"Manicure",nil];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Configure the cell...
NSString *identifier=nil;
NSString *task =[self.tasks objectAtIndex:indexPath.row];
NSRange urgentRange =[task rangeOfString:@"URGENT"];
if (urgentRange.location==NSNotFound) {
identifier =@"plainCell";
}
else
identifier=@"attentionCell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
UILabel *cellLabel=(UILabel *)[cell viewWithTag:1];
cellLabel.text=task;
return cell;
}
其他的时次要的,基本时都和前面的区别不大,就是table Data Source Methods
拖入控件后,选择表视图打开属性选择器 将最上方的Content中的Dynamic Prototypes改为Static Cells。将style设置为Grouped。选中单元块查看属性选择器,将Row修改为2
header 设为Silliest Colck Ever.
选择第一个单元格将属性检查器style修改为Left Detail ,将Title修改为The Date 第二单元格同理。
将控件和界面关联起来
选择Detail 按住control键拖入到右边的@interface和@end中间就会出现输出接口的IBOutlet,设计控件名称就OK。
在加载数据的时候去
NSDate *now = [NSDate date];
dataLabel.text=[NSDateFormatter localizedStringFromDate:now dateStyle:NSDateFormatterLongStyle timeStyle:NSDateFormatterNoStyle];
timeLabel.text=[NSDateFormatter localizedStringFromDate:now dateStyle:NSDateFormatterNoStyle timeStyle:NSDateFormatterLongStyle];
不过这里没有用到tabel Data Source Methods 方法,只要把这些方法注释掉即可。