ios 列表控制器

1    表格显示
        UITableViewController  通过tableView属性管理UITableView
                                                同时继承UITableViewDataSource协议 UITableViewDelegate协议
   (1) 简单显示
        在创建UITableViewController子类,覆盖:
        //返回表格行数
        - (NSInteger)tableView: (UITableView*)   numberOfRowsInSection: (NSInteger) 
        //创建单元显示内容
        - (UITableViewCell*)tableView:(UITableView*)tableView  cellForRowAtIndexPath:(NSIndexPath*)indexPath
        {
              static NSString* identifier = @"basis-cell";
              UITableViewCell* cell = [tableView   dequeueReusableCellWithIdentifier: identifier];
              if ( nil == cell ) {
                    cell = [[UITableViewCell alloc]   initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:identifier];
                    [cell autorelease];
              }
          cell.textLabel.text = [dataSource_ objectAtIndex:indexPath.row];
        return cell;
    }
     (2)选择动作          
        - (void)tableView:(UITableView*)tableView   didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
              NSString* message = [dataSource_ objectAtIndex:indexPath.row];
              UIAlertView* alert = [[[UIAlertView alloc] init] autorelease];
              alert.message = message;
              [alert addButtonWithTitle:@"OK"];
              [alert show];
        }
      (3) 分段显示:
        //返回段的数目
        - (NSInteger) numberOfSectionsInTableView: (UITableView*) 
        //返回对应段的段名
        - (NSString*)tableView: (UITableView*)   titleForHeaderInSection: (NSInteger) 
     (4) 分组显示
        改变表格显示的形式  默认 UITableViewStylePlain分段显示
            在init函数方法中:添加 self = [super   initWithStyle:   UITableViewStyleGrouped]
     (5) 段脚显示
        - (NSString*)tableView:(UITableView*)tableView   titleForFooterInSection: (NSInteger)section {
                return [keys_ objectAtIndex:section];    }
     (6)索引     表格右侧索引列表 
        - (NSArray*)sectionIndexTitlesForTableView: (UITableView*)tableView {
              return keys_;     }

2    单元定制
    (1) 尺寸与颜色 分隔线
         UITableView:
          self.tableView. backgroundColor  = [UIColor blackColor]; //< 背景颜色
          self.tableView. rowHeight  = 128.0; //< 单元的尺寸
          self.tableView. separatorColor  = [UIColor redColor]; //< 红色分隔线
          self.tableView. separatorStyle  = UITableViewCellSeparatorStyleNone;    //去除分割线
                                                                UITableViewCellSeparatorStyleSingleLine;
                                                                UITableViewCellSeparatorStyleSingleLineEtched

         UITabelViewCell:
            cell.textLabel.textColor = [UIColor whiteColor]; //< 文本颜色变成白色
            cell.textLabel.textAlignment = UITextAlignmentCenter; //< 中间对齐
            cell.textLabel.font = [UIFont systemFontOfSize:64]; //< 字体为64

     (3)追加图片
    //在单元的imageView属性中设置图片 images_ 是图片数组
          cell. imageView.image  = [images_ objectAtIndex:indexPath.row];

      (4) 追加细节
            static NSString* identifier = @" styles-subtitle";
            cell = [[UITableViewCell alloc]  initWithStyle: UITableViewCellStyleStyleSubtitle  reuseIdentifier:identifier];
UITableViewCellStyleStyleDefault  无详细节
UITableViewCellStyleStyleValue1   详细信息靠最后
UITableViewCellStyleStyleValue2   详细信息挨着标题
            cell. detailTextLabel.text  = [details_  objectAtIndex:indexPath.row];    //details_中保存副标题

     (5) 追加附件
            cell.accessoryType =   UITableViewCellAccessoryNone;        //无附件
UITableViewCellAccessoryDisclosureIndicator             //右箭头
UITableViewCellAccessoryDetail DisclosureButton      //右箭头按钮  今次有响应
UITableViewCellAccessoryCheckMark                          // 对勾
        - (void)tableView:(UITableView*)tableView 
                  accessoryButtonTappedForRowWithIndexPath: (NSIndexPath*)indexPath
        {
              //UIKitPrjCellWithDetail是另外创建的详细画面
              UIViewController* viewController = [[UIKitPrjCellWithDetail alloc] init];
              [self.navigationController pushViewController:viewController animated:YES];
              [viewController release];
        }

    (6)追加自定义附件
            UIButton* button = [UIButton buttonWithType:UIButtonTypeInfoDark];
            [button addTarget: self  action: @selector(  )  forControlE
vents: UIControlEventTouchUpInside];
            cell. accessoryView = button;

     (7) 追加仅编辑模式下显示的附件
         导航条:
        self.navigationItem.rightBarButtonItem = [self editButtonItem];
        self.tableView.editing = NO;
        self.tableView.allowsSelection = NO;
        self.tableView.allowsSelectionDuringEditing = YES;

        cell.editingAccessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        对单元未缩进的问题
            - (UITableViewCellEditingStyle)tableView:(UITableView*)tableView
               editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath
            {      return UITableViewCellEditingStyleNone;    }
            - (BOOL)tableView:(UITableView*)tableView
                shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath*)indexPath
            {    return NO;        }

    (8) 追加控件
        switch ( indexPath.section ) {
            case 0: //< 向单元中追加UIImageView
              [cell.contentView addSubview:[self imageViewForCell:cell withFileName:@"brows.png"]];
              break;
            case 1: //< 向单元中追加UISwitch
              [cell.contentView addSubview:[self switchForCell:cell]];
              break;
            case 2: //< 向单元中追加UISlider
              [cell. contentView addSubview:[self sliderForCell:cell]];
              break;
            default:
                  break;
          }

     (9)单元背景          
    self.tableView.backgroundColor = [UIColor clearColor];                            //背景色透明
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;     //隐藏单元分隔线

    UIImage* image = [UIImage imageNamed:@"frame.png"];
    UIImage* stretchableImage = [image stretchableImageWithLeftCapWidth:30 topCapHeight:30];
    UIImageView* imageView = [[[UIImageView alloc] initWithImage:stretchableImage] autorelease];
    cell. backgroundView = imageView;


 **********来自 《20搞定iphone软件开发一书》***********
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SQLAlchemy 是一个 SQL 工具包和对象关系映射(ORM)库,用于 Python 编程语言。它提供了一个高级的 SQL 工具和对象关系映射工具,允许开发者以 Python 类和对象的形式操作数据库,而无需编写大量的 SQL 语句。SQLAlchemy 建立在 DBAPI 之上,支持多种数据库后端,如 SQLite, MySQL, PostgreSQL 等。 SQLAlchemy 的核心功能: 对象关系映射(ORM): SQLAlchemy 允许开发者使用 Python 类来表示数据库表,使用类的实例表示表中的行。 开发者可以定义类之间的关系(如一对多、多对多),SQLAlchemy 会自动处理这些关系在数据库中的映射。 通过 ORM,开发者可以像操作 Python 对象一样操作数据库,这大大简化了数据库操作的复杂性。 表达式语言: SQLAlchemy 提供了一个丰富的 SQL 表达式语言,允许开发者以 Python 表达式的方式编写复杂的 SQL 查询。 表达式语言提供了对 SQL 语句的灵活控制,同时保持了代码的可读性和可维护性。 数据库引擎和连接池: SQLAlchemy 支持多种数据库后端,并且为每种后端提供了对应的数据库引擎。 它还提供了连接池管理功能,以优化数据库连接的创建、使用和释放。 会话管理: SQLAlchemy 使用会话(Session)来管理对象的持久化状态。 会话提供了一个工作单元(unit of work)和身份映射(identity map)的概念,使得对象的状态管理和查询更加高效。 事件系统: SQLAlchemy 提供了一个事件系统,允许开发者在 ORM 的各个生命周期阶段插入自定义的钩子函数。 这使得开发者可以在对象加载、修改、删除等操作时执行额外的逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值