如何使用 uitableviewcontroller

转载自:http://hi.baidu.com/taoofsong/item/fef493df3edda6dc251f40dd

如何使用 uitableviewcontroller?? 嘿嘿,简单的呢

我以前使用tableview视图,也是在uiview里面 加上一个表视图控件,偶然发现还有个 tableviewcontrollr。

 

如果你只需要使用一个表示图,那就使用tableviewcontroller把! 他很方便,很简洁!

 

使用方法很简单,shouxia首先在头文件加上2个 委托

@interface TestApp01AppDelegate : NSObject <UIApplicationDelegate,UITableViewDelegate,UITableViewDataSource> {

    

    UINavigationController *nav ;

    

    NSArray *array;

}

其次就是

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    // Override point for customization after application launch.

    

    array = [[NSArrayalloc] initWithObjects:@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1",@"1", nil];

    

    UITableViewController *table = [[UITableViewControlleralloc] initWithStyle:UITableViewStylePlain];

    

    table.tableView.dataSource =self;

    

    table.tableView.delegate = self;

    

    

    UIToolbar  *toolbar = [[UIToolbaralloc] initWithFrame:CGRectMake(0, 0,320, 30)];

    table.tableView.tableHeaderView = toolbar;

    

    

    [self.windowsetRootViewController:table];

    

    [self.windowmakeKeyAndVisible];

    

    

    returnYES;

}

然后给你 的cellfuy赋予内容 

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

{

    return [arraycount];

}

-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView

{

    return1;

}

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

{

    staticNSString *CellIdentifier = @"Cell";

    

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier] autorelease];

    }

    

    NSString  *string = [arrayobjectAtIndex:indexPath.row];

    

    

    cell.textLabel.text = string;

    

    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

    

    [cell.textLabelsetFont:[UIFontfontWithName:@"Georgia"size:27]];

    

    [cell.textLabelsetTextColor:[UIColorblueColor]];

    

    return cell;

}

ok了 

    table.tableView.dataSource =self;

    

    table.tableView.delegate = self;


注意这里


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值