- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是iPhone开发的新手。我有一个带有三个Section的UITableView,每个Section有三行。我有一个带有三个索引的UISegmentedControl。最初隐藏了tableview。当我选择segmentIndex的任何索引然后显示带有三个部分的tableview时。
但我的问题是,当我选择分段控件的索引时,其仅在一个部分中显示tableView的内容而其他两个部分则隐藏在tableView中。如何执行请回答
这是我的代码
#import "DetailViewController.h"
@interface DetailViewController ()
@end
@implementation DetailViewController
@synthesize tblView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//Customize tableview
tblView = [[UITableView alloc] init];
firstName = [NSArray arrayWithObjects:@"Parth",@"Bhadresh",@"Marshal", nil];
middleName = [NSArray arrayWithObjects:@"Dipakbhai",@"Dineshbhai",@"Mansukhbhai",nil];
lastName = [NSArray arrayWithObjects:@"Patel",@"Laiya",@"Kaneria", nil];
tblView.delegate = self;
tblView.dataSource = self;
}
-(void)viewWillAppear:(BOOL)animated
{
sgmtControl.frame = CGRectMake(17, 180, 285, 44);
tblView.frame = CGRectMake(0, 0, 320, 364);
tblView.hidden = YES;
[self.view addSubview:tblView];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
switch (section)
{
case 0:
return 3;
break;
case 1:
return 3;
break;
case 2:
return 3;
break;
}
return 0;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection: (NSInteger)section
{
switch (section)
{
case 0:
return @"FirstName";
break;
case 1:
return @"MiddleName";
break;
case 2:
return @"LastName";
break;
}
return nil;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *myIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:myIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myIdentifier];
}
switch (indexPath.section)
{
case 0:
cell.textLabel.text =[firstName objectAtIndex:indexPath.row];
break;
case 1:
cell.textLabel.text = [middleName objectAtIndex:indexPath.row];
break;
case 2:
cell.textLabel.text = [lastName objectAtIndex:indexPath.row];
break;
}
return cell;
}
-(IBAction)changeSegement:(id)sender
{
if(sgmtControl.selectedSegmentIndex == 0)
{
tblView.hidden = NO;
}
else if (sgmtControl.selectedSegmentIndex == 1)
{
tblView.hidden = NO;
}
else if (sgmtControl.selectedSegmentIndex == 2)
{
tblView.hidden = NO;
}
}
最佳答案
这样吧
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
switch (sgmtControl.selectedSegmentIndex)
{
case 0:
return [firstName count];
break;
case 1:
return [middleName count];
break;
case 2:
return [lastName count];
break;
}
return 0;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection: (NSInteger)section
{
switch (sgmtControl.selectedSegmentIndex)
{
case 0:
return @"FirstName";
break;
case 1:
return @"MiddleName";
break;
case 2:
return @"LastName";
break;
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *myIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:myIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myIdentifier];
}
switch (sgmtControl.selectedSegmentIndex)
{
case 0:
cell.textLabel.text =[firstName objectAtIndex:indexPath.row];
break;
case 1:
cell.textLabel.text = [middleName objectAtIndex:indexPath.row];
break;
case 2:
cell.textLabel.text = [lastName objectAtIndex:indexPath.row];
break;
}
return cell;
}
-(IBAction)changeSegement:(id)sender
{
if(sgmtControl.selectedSegmentIndex == 0)
{
tblView.hidden = NO;
}
else if (sgmtControl.selectedSegmentIndex == 1)
{
tblView.hidden = NO;
}
else if (sgmtControl.selectedSegmentIndex == 2)
{
tblView.hidden = NO;
}
[tblView reloadData];
}
关于ios - UITableView和UISegmentedControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15240242/
根据以下文档 ( https://developer.apple.com/documentation/uikit/uisegmentedcontrol/1618570-settitletextattr
我试图在登录时隐藏 nameTextField 并使其在注册时显示切换。我一直试图自己解决这个问题,但这就是我所得到的。我已经把它归结为两个错误,它们是相同的。 Issue Navigator laz
我有两个 UISegmentedControl,我想用其中一个来启用/禁用另一个。我编写了一个函数来处理这个问题,如下所示: - (void)disableSegment2 { if (
我有一个以编程方式定义的 UISegmentedControl。 我正在尝试添加布局约束,以便当我的 iPad 旋转时,分段控件在旋转 View 中正确调整大小,而不是溢出屏幕。 我应用了以下约束:
如何通过再次按下同一段来取消选择 UISegmented 控件中的给定段? 例如按下段 0,它将被选中并保持突出显示。再次按下段 0,它将变为未选中且未突出显示。 该控件仅触发 UIControlEv
我正在为我的分段控件设置颜色,如下所示: segmentedControl.backgroundColor = .gray segmentedControl.selectedSegmentTintCo
我在 iOS7 中更改分段控件的边框颜色时遇到问题。我在 stackoverflow 的其他地方找到了以下建议: [[UISegmentedControl appearance] setTit
是否可以让 UISegmentedControl 在 iPhone 上跨越两行?我已经在一些应用程序中看到了这一点,但没有在文档中找到我需要的内容。也许它是一个自定义的 UIButton,设计得像 U
我的应用程序中有一个 UISegmentedControl(请参阅下面的代码): // --------------- SETTING NAVIGATION BAR RIGHT BUTTONS NSA
我的 iPhone 应用程序中有一个分段控件,在 ios6 上运行良好,但在 ios7 上,分段图 block 被截断(有足够的空间容纳文本,但无论如何都会截断它们) self.segment
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: How to change font color of UISegmentedControl 是否可以为 selec
有没有办法通过编程使UIsegmentedControl具有方角?请帮忙!!! 最佳答案 您可以为将完全覆盖边框的片段设置背景图像。如果背景图像是方形的,那么分段控件将显示为方形。对您想要自定义的每个
如何制作多行 UISegmentedControl。我需要它有 6 个按钮,每行 3 个。我如何以编程方式执行此操作? 最佳答案 您将需要使用其中两个,并使用 selectedSegmentIndex
我正在使用带有一些自定义图像的 UISegmentedControl: UISegmentedControl *segmentedControl = [[UISegmentedControl allo
有没有办法摆脱 UISegmentedControl 的圆角或者它是默认行为? 最佳答案 有一些非常简单的方法可以让您摆脱 UISegmentedControl 上的圆形垃圾...将样式更改为“7”。
就像标签栏一样,我想在 UISegmentedControl 上显示徽章。因为我看不到 UISegmentedControl 的任何预定义方法,就像可用于 UITabBar 的方法一样。 我考虑过将徽
如何获得一个类似于邮件应用程序中的 UISegmentedControl,以便它与 UIToolbar 按钮颜色相同(就好像两个段都处于选定状态一样)。 我想使用分段控件来实现与 Mail 完全相同的
这可能是一个非常简单的问题,但我似乎无法在 API 或任何搜索引擎中找到任何内容。 我有一个分段控件,我已将其设置为瞬时,因为用户将选择他们想要搜索的几个汽车品牌。我遇到的问题是我似乎无法弄清楚如何识
当我将整个导航栏设置为黑色时,通常在所选按钮上的 UISegmentedControl 上显示的色调不会显示(self.navigationController.navigationBar.tintC
我想为 UISegmentedControl 提供以下方面: 注意灰色背景 View ,以及分段控件未选定项目的白色背景。 但是,如果我为 UISegmentedControl 提供白色背景,我会得到
我是一名优秀的程序员,十分优秀!