当前位置:  编程技术>移动开发
本页文章导读:
    ▪起步其他应用的activity        启动其他应用的activity 启动其他应用的activity,只需要两个东西。该应用的包名,被启动的activity的class全名。两个都是String类型。参考android文档: Intent android.content.Intent.setClassName(String packa.........
    ▪ 在tableViewTable中创办tableCell,不同分区含有不同数量的Cell(转)        在tableViewTable中创建tableCell,不同分区含有不同数量的Cell(转)  1、确定tableview中分分区数 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {     return 2; } 2、确定每个section中的cell数量 .........
    ▪ UITableView惯用知识总结(转)       UITableView常用知识总结(转) 1:tableviewcell的宽度设置 在你的自定义的tableviewcell的m文件里加入下面方法: ......

[1]起步其他应用的activity
    来源: 互联网  发布时间: 2014-02-18
启动其他应用的activity

启动其他应用的activity,只需要两个东西。该应用的包名,被启动的activity的class全名。两个都是String类型。参考android文档:

 Intent android.content.Intent.setClassName(String packageName, String className)

 还需一点:被启动的activity需设置标签:

 android:exported="true"

 

这样就够了!


    
[2] 在tableViewTable中创办tableCell,不同分区含有不同数量的Cell(转)
    来源: 互联网  发布时间: 2014-02-18
在tableViewTable中创建tableCell,不同分区含有不同数量的Cell(转)

 1、确定tableview中分分区数

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return 2;

}

2、确定每个section中的cell数量

 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    switch (section) {

        case 0:

            return 1;

            break;

        case 1 :

            return 1;

            break;

        default:

            break;

    }

    return 1;

}

3、确定Cell中的内容

 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath

{

    static NSString *CellIdentifier = @"Cell";

    

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    }

    

    // Configure the cell...

    

    switch (indexPath.section) {//哪一个分区

            

        case 0:

            switch (indexPath.row) {//分区中的哪一行

                case 0:

                    cell.textLabel.text=@"1";

                    break;

                    

                default:

                    break;

            }

            break;

        case 1:

            switch (indexPath.row) {//分区中的哪一行

                case 0:

                    cell.textLabel.text=@"66";

                    break;

                       

                default:

                    break;

            }

            break;

                default:

                    break;

            }

            break;

        default:

            break;

    }

    return cell;

}

4、点击cell时

 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

}

转载于:http://blog.sina.com.cn/s/blog_9ae642d70100xlyt.html


    
[3] UITableView惯用知识总结(转)
    来源: 互联网  发布时间: 2014-02-18
UITableView常用知识总结(转)
1:tableviewcell的宽度设置

在你的自定义的tableviewcell的m文件里加入下面方法:

view plain
  • -(void)layoutSubviews  
  • {  
  • [super layoutSubviews];  
  • CGRect frame = self.backgroundView.frame;  
  •     frame.origin.x += 18;  
  •     frame.size.width -= 36;  
  •     self.backgroundView.frame = frame;  
  •     frame = self.contentView.frame;  
  •     frame.origin.x += 18;  
  •     frame.size.width -= 36;  
  •     self.contentView.frame = frame;  
  • }  
  •  

    重写了tableviewcell的layoutSubviews的方法,调整一下backgroundview和contentview的frame就行了。
     
    UITableViewCell包含图像,文本等.

     

    NSString *CellIdentifier = [ [ NSString alloc ] initWithString: @"Frank" ];

    UITableViewCell *cell = [ [ [ UITableViewCell alloc ]

            initWithFrame: CGRectZero

            reuseIdentifier: CellIdentifier 

        ] autorelease

    ];

    然后你可以为每一个cell设置不同的风格

    (1) 显示文本: cell.text = @"Frank's Table Cell";

    (2) 对齐: cell.textAlignment = UITextAlignmentLeft;
    UITextAlignmentLeft 默认是左对齐

       UITextAlignmentRight 右对齐

       UITextAlignmentCenter 中对齐

    (3) 字体和尺寸:
    #import <UIKit/UIFont.h>

    UIFont *myFont = [ UIFont fontWithName: @"Arial" size: 18.0 ]; 

    cell.font = myFont;

    //系统字体

    UIFont *mySystemFont = [ UIFont systemFontOfSize: 12.0 ];

    UIFont *myBoldSystemFont = [ UIFont boldSystemFontOfSize: 12.0 ];

    UIFont *myItalicSystemFont = [ UIFont italicSystemFontOfSize: 12.0 ];

    (4) 颜色

    #import <UIKit/UIColor.h>

    //文本颜色

    cell.textColor = [ UIColor redColor ];

    //当前选择项的颜色

    cell.selectedTextColor = [ UIColor blueColor ];

    (5) 图像

    //从你应用程序目录下的文件创建一个image

    cell.image = [ UIImage imageNamed: @"cell.png" ];
    //当前选中项的图形

    cell.selectedImage = [ UIImage imageNamed: @"selected_cell.png" ];

    可以修改table保准行高来适应你的图形高度

    - (id)init 

    {

        self = [ super init ];

        if (self != nil) {

            self.tableView.rowHeight = 65; 

        }

        return self; 

    }

    你也可以为每一个cell定义不同的高度

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 

    {

        if ([ indexPath indexAtPosition: 1 ] == 0)

            return 65.0; 

        else

            return 40.0; 

    }

    (6)选中项的风格
    cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    UITableViewCellSelectionStyleBlue 默认选中项是蓝色

    UITableViewCellSelectionStyleGray 灰色

    UITableViewCellSelectionStyleNone 没有变化


    (7)标签 (labels)


    在偏移量100x0处创建一个尺寸50x50 label:

    UILabel *label = [ [ UILabel alloc ] initWithFrame: CGRectMake(100.0, 0.0, 50.0, 50.0) ];
    label.text = @"Label Text";
    label.textAlignment = UITextAlignmentLeft;
    label.textColor = [ UIColor redColor ];
    label.font = [ UIFont fontWithName: @"Arial" size: 10.0 ];

    标签label可以设置文本阴影,甚至可以定义阴影的偏移:

    label.shadowColor = [ UIColor grayColor ];
    label.shadowOffset = CGSizeMake(0, -1);

    高亮是的颜色:

    label.highlightedTextColor = [ UIColor blackColor ];
    标签的背景色:

    label.backgroundColor = [ UIColor blueColor ];

    把标签加到cell里

    [ cell addSubview: label ];

    (8) 附件
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; Style Description UITableViewCellAccessoryNone 没有附件 UITableViewCellAccessoryDisclosureIndicator 黑色向右的箭头 UITableViewCellAccessoryDetailDisclosureButton 蓝色附件按钮 UITableViewCellAccessoryCheckmark 复选框,支持选择

     

    7.3 实现多选
    - (void)tableView:(UITableView *)tableView
            didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    {
        NSLog(@"Selected section %d, cell %d", 
            [ indexPath indexAtPosition: 0 ], [ indexPath indexAtPosition: 1 ]); 
        //获的当前选择项
        UITableViewCell *cell = [ self.tableView cellForRowAtIndexPath: indexPath ]; 
        //显示复选框
        if (cell.accessoryType == UITableViewCellAccessoryNone)
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
        else
            cell.accessoryType = UITableViewCellAccessoryNone; 
    }
    7.4 编辑和删除
    在允许用户删除和编辑的时候,每一个cell左边会显示一个红色删除图标
    [ self.tableView setEditing:YES animated:YES ];
    关闭编辑的时候,table顶部会显示一个Edit导航条

    [ self.tableView setEditing: NO animated: YES ];

    在编辑过程中,如果用户要删除该项,会弹出一个删除确认框. 确认后调UITableViewDataSource类的commitEditingStyle方法来通知你的应用程序, 然后你可以从你的底层数据源里删除该项,并通知table view删除该行.
    - (void)tableView:(UITableView *)tableView
        commitEditingStyle:(UITableViewCellEditingStyle) editingStyle
        forRowAtIndexPath:(NSIndexPath *) indexPath 
    {
        if (editingStyle == UITableViewCellEditingStyleDelete) 
        {
            NSLog(@"Deleted section %d, cell %d", [ indexPath indexAtPosition: 0 ], [ indexPath indexAtPosition: 1 ]);
            NSMutableArray *array = [ [ NSMutableArray alloc ] init ];
            [ array addObject: indexPath ];
            [ self.tableView deleteRowsAtIndexPaths: array
                withRowAnimation: UITableViewRowAnimationFade 
            ];
         }
    }

    通过传递一个数组给deleteRowsAtIndexPaths方法, 可以删除一行或多行.

     

    withRowAnimation至此下列预定义的删除动画

     

    Animation Description UITableViewRowAnimationFade Cell fades out UITableViewRowAnimationRight Cell slides out from right UITableViewRowAnimationLeft Cell slides out from left UITableViewRowAnimationTop Cell slides out to top of adjacent cell UITableViewRowAnimationBottom Cell slides out to bottom of adjacent cell

     

    7.5 重新加载表
    当你的数据变了的时候,你可以重新加载整个表
    [ self.tableView reloadData ];
    7.6 TableDemo: Simple File Browser

    这个例子列表你应用程序home目录里的文件和目录

     

    (1) TableDemo main (main.m)
    #import <UIKit/UIKit.h>
    int main(int argc, char *argv[])
    {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
        int retVal = UIApplicationMain(argc, argv, nil, @"TableDemoAppDelegate");
        [pool release];
        return retVal; 
    }

    (2)TableDemo application delegate

    prototypes (TableDemoAppDelegate.h)

     

    #import <UIKit/UIKit.h>
    @class TableDemoViewController;
    @interface TableDemoAppDelegate : NSObject <UIApplicationDelegate> 
    {
        UIWindow *window;
        TableDemoViewController *viewController;
        UINavigationController *navigationController;
    }
    @property (nonatomic, retain) IBOutlet UIWindow *window;
    @property (nonatomic, retain) IBOutlet TableDemoViewController *viewController;
    @end

    (TableDemoAppDelegate.m)

    #import "TableDemoAppDelegate.h"
    #import "TableDemoViewController.h"
    @implementation TableDemoAppDelegate
    @synthesize window;
    @synthesize viewController;
    - (void)applicationDidFinishLaunching:(UIApplication *)application {
        CGRect screenBounds = [ [ UIScreen mainScreen ] bounds ];
        self.window = [ [ [ UIWindow alloc ] initWithFrame: screenBounds ] autorelease ];
        viewController = [ [ TableDemoViewController alloc ] init ];
        navigationController = [ [ UINavigationController alloc ] init
            WithRootViewController: viewController
        ];
        [ window addSubview: [ navigationController view ] ];
        [ window makeKeyAndVisible ];
    }
    - (void)dealloc {
        [viewController release];
        [window release];
        [super dealloc];
    }
    @end

    (3) TableDemo view controller

    prototype (TableDemoViewController.h)

    #import <UIKit/UIKit.h>
    @interface TableDemoViewController : UITableViewController {
        NSMutableArray *fileList;
    }
    - (void) startEditing;
    - (void) stopEditing;
    - (void) reload;
    @end

    (TableDemoViewController.m)

    #import "TableDemoViewController.h"
    @implementation TableDemoViewController 
    - (id)init {
        self = [ super init ];
        if (self != nil) {
            [ self reload ];
            self.navigationItem.rightBarButtonItem = [ [ [ UIBarButtonItem alloc ]
                initWithBarButtonSystemItem: UIBarButtonSystemItemEdit
                target: self
                action: @selector(startEditing)
                ] autorelease 
            ];
            self.navigationItem.leftBarButtonItem = [ [ [ UIBarButtonItem alloc ]
                initWithTitle:@"Reload"
                style: UIBarButtonItemStylePlain
                target: self
                action:@selector(reload) 
                ] autorelease
            ]; 
        }
        return self;
    }
    - (void) stopEditing {
        [ self.tableView setEditing: NO animated: YES ];
        self.navigationItem.rightBarButtonItem
        = [ [ [ UIBarButtonItem alloc ]
           initWithBarButtonSystemItem: UIBarButtonSystemItemEdit
           target: self
           action: @selector(startEditing) ] autorelease ];
    }
    
    
    - (void) reload {
        NSDirectoryEnumerator *dirEnum;
        NSString *file;
        fileList = [ [ NSMutableArray alloc ] init ];
        dirEnum = [ [ NSFileManager defaultManager ] enumeratorAtPath:
            NSHomeDirectory()
        ];
        while ((file = [ dirEnum nextObject ])) {
            [ fileList addObject: file ];
        }
        [ self.tableView reloadData ];
    }
    
    
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return 1;
    }
    
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsIn
    Section:(NSInteger)section {
        return [ fileList count ];
    }
    
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRow
    AtIndexPath:(NSIndexPath *)indexPath {
    
    
        NSString *CellIdentifier = [ fileList objectAtIndex:
            [ indexPath indexAtPosition: 1 ]
        ];
        UITableViewCell *cell = [ tableView
            dequeueReusableCellWithIdentifier: CellIdentifier
        ];
        if (cell == nil) {
            cell = [ [ [ UITableViewCell alloc ] initWithFrame:
                CGRectZero reuseIdentifier: CellIdentifier ] autorelease
            ];
            cell.text = CellIdentifier;
            UIFont *font = [ UIFont fontWithName: @"Courier" size: 12.0 ];
            cell.font = font;
        }
        return cell;
    }
    
    
    - (void)tableView:(UITableView *)tableView
        commitEditingStyle:(UITableViewCellEditingStyle) editingStyle
        forRowAtIndexPath:(NSIndexPath *) indexPath
    {
        if (editingStyle == UITableViewCellEditingStyleDelete) {
            
            UITableViewCell *cell = [ self.tableView cellForRowAtIndexPath:
                indexPath ];
            for(int i = 0; i < [ fileList count ]; i++) {
                if ([ cell.text isEqualToString: [ fileList objectAtIndex: i ] ]) {
                    [ fileList removeObjectAtIndex: i ];
                }
            }
            
            NSMutableArray *array = [ [ NSMutableArray alloc ] init ];
            [ array addObject: indexPath ];
            [ self.tableView deleteRowsAtIndexPaths: array
                withRowAnimation: UITableViewRowAnimationTop
            ];
    
    
        }
    }
    
    
    - (void)tableView:(UITableView *)tableView didSelectRowAt
    IndexPath:(NSIndexPath *)indexPath {
        UITableViewCell *cell = [ self.tableView cellForRowAtIndexPath: indexPath ];
        UIAlertView *alert = [ [ UIAlertView alloc ] initWithTitle: @"File Selected"
            message: [ NSString stringWithFormat: @"You selected the file '%@'",
                           cell.text ]
            delegate: nil
            cancelButtonTitle: nil
            otherButtonTitles: @"OK", nil
        ];
        [ alert show ];
    }
    - (void)loadView {
        [ super loadView ];
    }
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterface
    Orientation)interfaceOrientation {
        return YES;
    }
    - (void)didReceiveMemoryWarning {
        [ super didReceiveMemoryWarning ];
    }
    - (void)dealloc {
        [ fileList release ];
        [ super dealloc ];
    }
    @end

     

    转载自:http://blog.sina.com.cn/s/articlelist_1654117677_0_1.html(这个作者还有很多关于tableview的使用指南,赞一个!!!用到常看看)


        
    最新技术文章:
    ▪Android开发之登录验证实例教程
    ▪Android开发之注册登录方法示例
    ▪Android获取手机SIM卡运营商信息的方法
    ▪Android实现将已发送的短信写入短信数据库的...
    ▪Android发送短信功能代码
    ▪Android根据电话号码获得联系人头像实例代码
    ▪Android中GPS定位的用法实例
    ▪Android实现退出时关闭所有Activity的方法
    ▪Android实现文件的分割和组装
    ▪Android录音应用实例教程
    ▪Android双击返回键退出程序的实现方法
    ▪Android实现侦听电池状态显示、电量及充电动...
    ▪Android获取当前已连接的wifi信号强度的方法
    ▪Android实现动态显示或隐藏密码输入框的内容
    ▪根据USER-AGENT判断手机类型并跳转到相应的app...
    ▪Android Touch事件分发过程详解
    ▪Android中实现为TextView添加多个可点击的文本
    ▪Android程序设计之AIDL实例详解
    ▪Android显式启动与隐式启动Activity的区别介绍
    ▪Android按钮单击事件的四种常用写法总结
    ▪Android消息处理机制Looper和Handler详解
    ▪Android实现Back功能代码片段总结
    ▪Android实用的代码片段 常用代码总结
    ▪Android实现弹出键盘的方法
    ▪Android中通过view方式获取当前Activity的屏幕截...
    ▪Android提高之自定义Menu(TabMenu)实现方法
    ▪Android提高之多方向抽屉实现方法
    ▪Android提高之MediaPlayer播放网络音频的实现方法...
    ▪Android提高之MediaPlayer播放网络视频的实现方法...
    ▪Android提高之手游转电视游戏的模拟操控
     


    站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3