UIButton分组的按钮 [英] UIButton grouped Buttons
问题描述
我正在尝试创建一个完全像这样的按钮:
I'm trying to create a button set up exactly like this:
我该怎么做?有人可以告诉我代码吗?有没有办法像这样分组" UIButton?
How would I do this? Can someone show me the code? Is there a way to "Group" UIButtons like this?
推荐答案
您将要使用UITableViewController
,并将节设置为UITableViewStyleGrouped
.
You'll want to use a UITableViewController
with the sections set to be UITableViewStyleGrouped
.
每个组都是一个部分,因此您需要返回使用- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
的部分.
Each of the groups is a section, so you'll want to return how many sections you have with - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
.
对于每个部分,您都希望使用- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
指定多少行.
For every section, you want to specify how many rows there are with - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
.
您将要使用- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
自定义每个单元格(顺便说一句,它告诉您要在indexPath
变量中修改哪个节的特定行).
You'll want to customize each cell with - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
(which, by the way, tells you which section's particular row you're modifying in the indexPath
variable).
最后,您将使用XCode为您提供的模式来处理- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
中的行单击:
Finally, you'll want to handle the row click in - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
, using the pattern XCode provides for you:
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
希望这会有所帮助!
这篇关于UIButton分组的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!