从零开始学习iOS开发-股票记帐本1.0(1)
来源:互联网 发布:声鉴软件 编辑:程序博客网 时间:2024/05/01 14:42
自己的第一个App的1.0版本终于新鲜出炉了(虽然现在还在审核中)。
下面将开发中遇到的问题做一个小小的纪录吧。
1. Table View在ViewController中的使用
1) 在storyboard中,设置tableview的datasource和delegate
2) .h文件中,
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
如果是使用默认的cell,则
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *cellIdentifier=@"cellIdentifier"; UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier ]; if (cell==nil) { cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; } cell.textLabel.text=@"hello"; return cell;}
2. 导入自定义nib文件
在viewDidLoad中
UITableView *tableView=(id)[self.view viewWithTag:1]; tableView.rowHeight=80; UINib *nib=[UINib nibWithNibName:@"stockTradeTableViewCell" bundle:nil]; [tableView registerNib:nib forCellReuseIdentifier:cellIdentifier];
此外,还需要在
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
中定义
stockTradeTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
3. 代理模式
A窗口打开了B窗口,而在程序进行中B想与A联络(可以参考《iOS Learning 2》第9章)。
1)在B.h中定义protocol
@protocol addStockViewControllerDelegate <NSObject>- (void)addStockViewControllerDidCancel:(addStockViewController *)controller;- (void)addStockViewController:(addStockViewController *)controller didFinishAddingStockData:(stockData *)stockdata;@end
2)在B.h中定义代理协议的变量属性
@property (weak, nonatomic)id<addStockViewControllerDelegate>delegate;
3)让B在合适的时候向A发送消息,即在恰当的位置使用protocol中定义的方法
[self.delegate addStockViewController:self didFinishAddingStockData:stockdata ];
4)让A遵从代理协议,在@interface后添加;并在.m文件中添加方法描述
5)通知B,现在A现在是B的代理了
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ if ([segue.identifier isEqualToString:@"addStock"]) { UINavigationController *navigationController=segue.destinationViewController;//新的视图控制器可以在segue.destinationViewController中找到 addStockViewController *controller=(addStockViewController *)navigationController.topViewController;//为了获取addStockViewController对象,我们可以查看导航控制器的topViewController属性,该属性指向导航控制器的当前活跃界面 controller.delegate=self;//一旦我们获得了到addStockViewController对象的引用,就需要将delegate属性设置为self(这样在addStockViewController中的self.delegate才是stockTradeViewController),而self指的是stockTradeViewController } else if([segue.identifier isEqualToString:@"sellStock"]){ sellStockViewController *controller=segue.destinationViewController; controller.delegate=self; controller.stockdata=sender; }}
0 0
- 从零开始学习iOS开发-股票记帐本1.0(1)
- 从零开始学习iOS开发-股票记帐本1.0(2)
- 从零开始学习iOS开发-股票记帐本1.0(3)
- 从零开始学习iOS开发-股票记帐本1.0(4)
- 从零开始学习股票知识
- 从零开始学习股票知识
- 从零开始学习iOS开发1:认识xcode
- Easy-记帐 易记帐 iOS app 启动
- 记帐本《血汗钱》
- 专业的个人记帐软件 爱上记帐 1.0.1
- Android之股票开发学习
- 从零开始学习Android开发-Android概览
- [Android开发从零开始].15.Service学习(1)
- 股票基金学习1
- 从零开始复习股票知识
- 从零开始学股票
- 三十而立,从零开始学ios开发
- 三十而立,从零开始学ios开发
- /sys/class/gpio 文件接口操作IO端口(s3c2440)
- CSS3属性box-flex
- hdoj5253
- OC_Notifications(通知)
- IO流笔记02
- 从零开始学习iOS开发-股票记帐本1.0(1)
- 【CF 474E】Pillars
- Practice Round APAC test Problem A. Bad Horse 2-sat
- 使用专用硬件加速深度卷积神经网络
- 风险投资与经营者 分成利润
- 正则表达式知识点汇集
- NGUI 无法刷新 shader参数的问题
- HDU 2032
- RMAN正确地删除Archivelog以及设置有备库的归档删除策略