如何使用 uitableviewcontroller

来源:互联网 发布:windows正版验证补丁 编辑:程序博客网 时间:2024/06/02 04:19

转载自: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;


注意这里

#Ios

原创粉丝点击