本文主要是介绍从零开始学习iOS开发-股票记帐本1.0(3),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
6. 设置文本输入框的默认键盘
storyboard-Attributes inspector-Keyboard Type
7. 将字符串中的数字转换为float类型
float float=[string floatValue];
8. 获取系统时间
- (NSString *)sellStockDate{NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];[dateFormatter setDateFormat:@"yyyy年MM月dd日"];return [dateFormatter stringFromDate:[NSDate date]];
}
9. 设置字体颜色以及保留小数点后的位数
cell.gainOrLose.text=[NSString stringWithFormat:@"+%.0f",ValueOfGainOrLose];cell.gainOrLose.textColor=[UIColor colorWithRed:1 green:0 blue:0 alpha:1];
10. 实现tableview的横扫删除
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{[self.dataModel.Data removeObjectAtIndex:indexPath.row];NSArray *indexPaths = @[indexPath];[tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];[self.dataModel saveData];
}
11. 取消cell的选中状态
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
12. 添加搜索框
可以参考这个网址:http://www.tuicool.com/articles/6viqEn
1)在.h文件中
<UISearchBarDelegate,UISearchResultsUpdating>
在.m文件中
2)
@property (strong, nonatomic) UISearchController *searchController;
3)初始化
_searchController=[[UISearchController alloc]initWithSearchResultsController:nil];
_searchController.searchResultsUpdater=self;_searchController.dimsBackgroundDuringPresentation=NO;_searchController.hidesNavigationBarDuringPresentation=NO;_searchController.searchBar.frame=CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 40);self.tableview.tableHeaderView=self.searchController.searchBar;
4)判断搜索时的tableview
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{if (self.searchController.active) {return [self.searchData count];}else{return [self.dataModel.Data count];}
}
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController{NSString *searchString = [self.searchController.searchBar text];if (self.searchData!= nil) {[self.searchData removeAllObjects];}
// NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF CONTAINS[c] %@", searchString];//过滤数据
// self.searchData= [NSMutableArray arrayWithArray:[self.dataModel.Data filteredArrayUsingPredicate:predicate]];self.searchData=[[NSMutableArray alloc]initWithCapacity:20];for (NSUInteger i=0;i<[self.dataModel.Data count];i++) {stockData *stockdata=self.dataModel.Data[i];if ([stockdata.nameOfStock containsString:searchString]) {[self.searchData addObject:self.dataModel.Data[i]];}}[self.tableview reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{......if (self.searchController.active) {stockdata=self.searchData[indexPath.row];}else{stockdata=self.dataModel.Data[indexPath.row];}......}
这篇关于从零开始学习iOS开发-股票记帐本1.0(3)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!