UITableView创建

来源:互联网 发布:马云的淘宝怎么赚钱的 编辑:程序博客网 时间:2024/06/05 22:41

  appdelegate.m



- (void) dealloc

{

    

    [_windowrelease];

   _window = nil;

    [superdealloc];

    

    

}




  FirstViewController * first = [[FirstViewControlleralloc] init];

    

    UINavigationController * nav = [[UINavigationControlleralloc] initWithRootViewController:first];

    

    [_windowsetRootViewController:nav];

    

    [firstrelease];

    [navrelease];



UIViewController.h

添加 协议 

<UITableViewDataSource,UITableViewDelegate>



.m

#import "FirstViewController.h"


@interface FirstViewController ()


@end


@implementation FirstViewController


- (void) dealloc

{

    

    

    [superdealloc];

    

}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

   self = [superinitWithNibName:nibNameOrNil bundle:nibBundleOrNil];

   if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    [superviewDidLoad];

// Do any additional setup after loading the view.

    

    UITableView * tableView = [[UITableViewalloc] initWithFrame:CGRectMake(0,0, 320,416) style:UITableViewStylePlain];

    [tableView setBackgroundColor:[UIColororangeColor]];

    [tableViewsetDataSource:self];

    [tableViewsetDelegate:self];

    [self.viewaddSubview:tableView];

    [tableViewrelease];

    

    

    self.navigationController.navigationBar.translucent = NO;

    

}




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

{

    

    

   return 10;

    

    

}




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

{

    

   static NSString * cellIdentify =@"cellIdentify";

   UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];

    

   if (cell == NULL) {

        cell = [[[UITableViewCellalloc] initWithStyle:UITableViewCellStyleValue1reuseIdentifier:cellIdentify] autorelease];

        

    }

    [cell.textLabelsetText:@"骚委"];

    [cell.textLabelsetTextColor:[UIColororangeColor]];

   return cell;

    

}







@end











0 0
原创粉丝点击