標籤:fse ack tla 需要 style ext data 建立 sar
第一條:UITableViewCell 內容的設定//文本放到最後NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_dataArr.count - 1 inSection:0];[_tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES]; //重新整理指定cellNSIndexPath *indexPath_3=[NSIndexPath indexPathForRow:0 inSection:2];NSArray *indexArray3=[NSArray arrayWithObject:indexPath_3];[self.tableview reloadRowsAtIndexPaths:indexArray3 withRowAnimation:UITableViewRowAnimationAutomatic]; 第二條:UITableViewCell分割線左邊部分缺少一些的解決方案-(void)viewDidLayoutSubviews { if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) { [self.tableView setSeparatorInset:UIEdgeInsetsZero]; } if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) { [self.tableView setLayoutMargins:UIEdgeInsetsZero]; }} -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { [cell setLayoutMargins:UIEdgeInsetsZero]; } if ([cell respondsToSelector:@selector(setSeparatorInset:)]){ [cell setSeparatorInset:UIEdgeInsetsZero]; }} 第三條:UITableView的分割線部分不顯示的問題?simulator -> debug -> optimize rendering for window scale 取消打勾就好 第四條: 自訂cell分割線大致用到的兩種方法 a、把自訂的分割線當成一個View放到cell的contentView上,一定要注意重用問題,所以這個view 要在cell初始化的時候添加上。範例程式碼如下:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath * )indexPath{
UITableViewCell *cell =nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell ==nil) {
cell= [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
cell.accessoryView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"huicellacce"]];
cell.backgroundColor = [UIColor clearColor];
//cell.selected = YES;
UIImageView *imageViewSepE = [[UIImageView alloc]initWithFrame:CGRectMake(47, 49, 200, 1)];
imageViewSepE.image = [UIImage imageNamed:@"godline"];
[cell.contentView addSubview:imageViewSepE];
}
return cell;
}
b、比較複雜,用到了底層的架構
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor); CGContextFillRect(context, rect);
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextStrokeRect(context, CGRectMake(5, -1, rect.size.width - 10, 1)); //下分割線
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGContextStrokeRect(context, CGRectMake(5, rect.size.height, rect.size.width - 10,1));
}
第五條: 用代碼的方式自定製cell,必須寫initWithStyle的方法- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { /*** 這裡寫要添加控制項 ***/ } return self;} 【iOS開發TableView】TabelView自訂cell 第一種:通過建立xib檔案。 ①首先建立xib檔案 ②建立xib檔案對應 的模型A,名字與xib檔案一樣,並繼承UITableViewCell類,並實現cellWithTableView的構造方法。 ③在interface builder裡更改xib檔案預設的類,為第二步建立的模型類。 ④建立資料模型B,並且A中包含資料模型B ⑤A通過懶載入B方法(就是重寫B對象的setter方法)將控制項賦值。 第二種:代碼自訂cell ①建立一個繼承UITableViewCell的類,裡面擁有frame模型 ②重寫initWithStyle:reuseIdentifier:方法(添加所有需要顯示的子控制項(不需要設定子控制項的資料和frame, 子控制項要添加到contentView中,還有添加屬性設定). ③建立資料模型 ④建立frame模型(擁有資料模型) ⑤重寫資料模型對象的setter方法,然後再裡面設定控制項大小,和cell的高度。 ⑥控制器擁有frame對象數組。出事Cell的時候直接賦值給cell.frame對象就行。 第六條:iOS開發 - 讓tableView不能下拉重新整理,可以上拉載入1. 首先遵循代理 UIScrollViewDelegate2.實現代理方法即可-(void)scrollViewDidScroll:(UIScrollView*)scrollView{ if (tabelView.contentOffset.y <= 0) { tabelView.bounces = NO; }else { tabelView.bounces = YES; }} 第七條:去除UITableView底部多餘行及分割線self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
iOS開發,UITableView相關問題