UITableView与UITableViewCell的使用

来源:互联网 发布:淘宝行业分析软件 编辑:程序博客网 时间:2024/05/16 09:24
<pre name="code" class="objc">DataSource //设置<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px;">DataSource协议代理人</span>
Delegate //设置UITableView是协议代理人
 DataTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 420)]; //设置布局[DataTable setDelegate:self];[DataTable setDataSource:self];[self.view addSubview:DataTable];[DataTable release];
//设置每个分区标题栏
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{return TitleData;}
//指定有多少个分区(Section),默认为1- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {return 4;}

//绘制Cell-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {static NSString *SimpleTableIdentifier = @”SimpleTableIdentifier”;    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:                            SimpleTableIdentifier];   if (cell == nil) {         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault                                      reuseIdentifier: SimpleTableIdentifier] autorelease];}cell.imageView.image=image;//未选cell时的图片cell.imageView.highlightedImage=highlightImage;//选中cell后的图片cell.text=//…..return cell;}
在UITableViewCell上建立UILable多行显示- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {   static NSString *CellIdentifier = @”Cell”;      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];   if (cell == nil) {       cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; UILabel *Datalabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 320, 44)]; [Datalabel setTag:100]; Datalabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; [cell.contentView addSubview:Datalabel]; [Datalabel release];} UILabel *Datalabel = (UILabel *)[cell.contentView viewWithTag:100];[Datalabel setFont:[UIFont boldSystemFontOfSize:18]];Datalabel.text = [data.DataArray objectAtIndex:indexPath.row];cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;   return cell;}




0 0
原创粉丝点击