1.cell下的横线的方法:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
2.在UITableView中直接添加contentView的子属性的做法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * cellID = @"cellIdentifier";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
}
else {
while ([cell.contentView.subviews lastObject ]!=nil) {
[(UIView*)[cell.contentView.subviews lastObject]removeFromSuperview];
}
}
cell.detailTextLabel.text = _dataSource[indexPath.row][@"title"];
// cell.imageView.image = [UIImage imageNamed:_dataSource[indexPath.row][@"image"]];
UIImageView *cellImgV = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 80, 80)];
cellImgV.image = [UIImage imageNamed:_dataSource[indexPath.row][@"image"]];
[cell.contentView addSubview:cellImgV];
return cell;
}
3.忽略(ignore)已知的警告
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
/**
* //已知的一些编译警告类型
-Wincompatible-pointer-types 指针类型不匹配
-Wincomplete-implementation 没有实现已声明的方法
-Wprotocol 没有实现协议的方法
-Wimplicit-function-declaration 尚未声明的函数(通常指c函数)
-Warc-performSelector-leaks 使用performSelector可能会出现泄漏(该警告在xcode4.3.1中没出现过,网上流传说4.2使用performselector:withObject: 就会得到该警告)
-Wdeprecated-declarations 使用了不推荐使用的方法(如[UILabel setFont:(UIFont*)])
-Wunused-variable 含有没有被使用的变量
*/
// 这里是代码
#pragma clang diagnostic pop
4.iOS打开和预览pdf文档的方法:
http://code.tutsplus.com/tutorials/ios-sdk-previewing-and-opening-documents--mobile-15130
5.将URL中的不可用字符转化为可用字符的方法
- (void)loadSandwiches {
NSString* path = [[NSBundle mainBundle] pathForResource: @"Sandwiches"
ofType: @"json"];
NSString* data = [NSString stringWithContentsOfFile: path
encoding: NSUTF8StringEncoding
error: nil];
NSData* resultData = [data dataUsingEncoding:NSUTF8StringEncoding];
_sandwiches = [NSJSONSerialization JSONObjectWithData:resultData
options:kNilOptions error:nil];
}
6.UITableView选中跳转的另一种方法
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
SandwichViewController* sandwichVC = (SandwichViewController*)segue.destinationViewController;
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
sandwichVC.sandwich = [self sandwiches][path.row];
}
7.从AppDelegate中获取其中的属性 sandwiches(数组类型)
- (NSArray*) sandwiches
{
AppDelegate * appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
return appDelegate.sandwiches;
}
8.(label)和文字相关的属性:
adjustsFontSizeToFitWidth属性
父视图改变时子视图随着改变
autoresizingMask属性
isDescendantOfView: 方法 : 判断一个视图是不是另一个视图的子视图
9.比较字符串 <升序>
sortedArrayUsingSelector:@selector(localizedStandardCompare:)
10.Uncomment the following line to preserve selection between presentations.
self.clearsSelectionOnViewWillAppear = NO;
11.UITableView分割线样式与颜色
tv.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
tv.separatorColor = [UIColor colorWithRed:52.0f/255.0f green:53.0f/255.0f blue:61.0f/255.0f alpha:1];
12.更新myTableview并显示最后一行
if (dataArray.count > 0) {
[myTableView reloadData];
// reloadData后不能直接调用scrollToRowAtIndexPath,有可能lastIndex在table中不存在,
// 所以要[NSObject performBlock: afterDelay:0];
[myTableView retain]; // 防止关闭视图,myTableView释放之后scrollToBottom出错
NSIndexPath *lastIndex = [NSIndexPath indexPathForRow:dataArray.count-1 inSection:0];
void (^scrollToBottom)(void) = ^{
[myTableView scrollToRowAtIndexPath:lastIndex atScrollPosition:UITableViewScrollPositionBottom animated:YES];
[myTableView release];
};
[NSObject performBlock:scrollToBottom afterDelay:0];