xcode 4.3.2 storyboard绘制UITableView为理解storyboard使用和tableview有用

1.Xcode新建single view application


2.删除storyboard里的默认viewcontroller


3.拖入table view controller,拖入一个table view cell

[选中刚刚拖入的table view cell

3.1 修改Table View Cell属性中的Identifier为:myCell,此后此标志需要在myTableViewController.m中用于程序控制,来引用本单元格,并设置数据其中

3.2 目前table view的Content参数还是缺省的Dynamic Prototypes,设置了static cells会出错,待考究,有知道的朋友请留言告知下谢谢,我也是刚玩iOS开发_ _

可以设置table view的Style参数为Grouped

]


4.菜单:editor->embed in->navigation controller


*5 此步骤也可以不做:拖入tab bar controller到storyboard

*5.1 删除tab bar controller下的两个view controller

*5.2 按住cntrol键,从tab bar controller拉线到navigation controller,弹出对话框中选中“Relationship->viewControllers”

*5.3 选中tab bar controller,设置属性:选中is Initial View Controller,让tab bar controller成为初始化的view controller


6 新建File,Cocoa Touch->Objective-C class

设置Class:myTableViewController

设置Subclass of: UITableViewController

//myTableViewController继承UITableViewController


7 编辑myTableViewController.h

将类:myTableViewController定义完整如下:


@interfacemyTableViewController :UITableViewController

{

NSMutableArray*lists; //新增,用于定义表格中显示的内容

}


@property(nonatomic,strong)NSMutableArray*lists; //新增



8 修改myTableViewController.m

@implementationmyTableViewController


@synthesizelists; //新增加


- (void)viewDidLoad

{

[superviewDidLoad];

    //下面新增:定义lists数据
 
 

self.title=@"Lists";

lists= [[NSMutableArrayalloc]initWithCapacity:20];

[listsaddObject:@"test1"];

[listsaddObject:@"test2"];

[listsaddObject:@"test3"];

[listsaddObject:@"test4"];

[listsaddObject:@"test5"];


}


//下面三个函数新建myTableViewControll文件后,已经生成

- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView

{

//删除此行 #warning警告行

// Return the number of sections.

return1;

}


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

{

//删除此行#warning Incomplete method implementation.

// Return the number of rows in the section.

return[self.listscount];

}



//下面这个函数,用于实现表格中数据的显示

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

{

staticNSString*CellIdentifier =@"myCell";//修改此标志,storyboard中设置此标志,不能写错,否则表格中不会显示lists数据。

UITableViewCell*cell = [tableViewdequeueReusableCellWithIdentifier:CellIdentifier];

// Configure the cell...

//增加下面的cell配置,让在标志为“myCell"的单元格中显示list数据

NSIntegerrow = [indexPathrow];

cell.textLabel.text= [self.listsobjectAtIndex:row];

returncell;

}


另外一种方法,navigation controller后面挂接普通的view controller容器,容器里拖入table view 和table view cell。

这种方法:新建view controller容器对应的controller.h 和.m文件,.h文件中的类需要继承UITableViewController的datasource 和 delegate, 在.m文件中,需要实现第一中方法中的后面三种方法即可。

numberOfSectionsInTableView()

numberOfRowsInSection()

cellForRowAtIndexPath()

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值