段控制在 iPhone 中不起作用
我是一个新人,使用段控制器来查看表格,我的表格根据所选段而变化...
这是代码...问题是当我选择任何段时..它没有向我显示任何内容..
- (void)viewDidLoad {
segArrayOne = [[NSMutableArray alloc] initWithObjects:@"A",@"B",@"C",nil];
segArrayTwo = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",nil];
segArrayThree = [[NSMutableArray alloc] initWithObjects:@"A1",@"A2",@"A3",@"A4",@"A5",nil];
dummyArray = [[NSMutableArray alloc] init];
tableDummy = [[UITableView alloc] initWithFrame:CGRectMake(0,80,320,400) style:UITableViewStyleGrouped];
tableDummy.delegate = self;
tableDummy.dataSource = self;
//
dummyArray=segArrayOne;
[self.view addSubview:tableDummy];
tableDummy.scrollEnabled=NO;
//[tableDummy release];
[segmentedController addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventValueChanged];
[super viewDidLoad];
}
-(IBAction)buttonPressed:(id)sender{
selectedSegment = [segmentedController selectedSegmentIndex];
switch (selectedSegment) {
case 0:
dummyArray=segArrayOne;
break;
case 1:
dummyArray=segArrayTwo;
break;
case 2:
dummyArray=segArrayThree;
break;
default:
//dummyArray=segArrayOne;
break;
}
NSLog(@"%@",dummyArray);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"%@",dummyArray);
return [dummyArray count];
//return @"";
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [dummyArray objectAtIndex:indexPath.row];
return cell;
}
I am a new bie and using segment controlller to see the table and my table changes according to the selected segment...
here is the code...and problem is when I select any segment..it is not showing me anything..
- (void)viewDidLoad {
segArrayOne = [[NSMutableArray alloc] initWithObjects:@"A",@"B",@"C",nil];
segArrayTwo = [[NSMutableArray alloc] initWithObjects:@"1",@"2",@"3",@"4",nil];
segArrayThree = [[NSMutableArray alloc] initWithObjects:@"A1",@"A2",@"A3",@"A4",@"A5",nil];
dummyArray = [[NSMutableArray alloc] init];
tableDummy = [[UITableView alloc] initWithFrame:CGRectMake(0,80,320,400) style:UITableViewStyleGrouped];
tableDummy.delegate = self;
tableDummy.dataSource = self;
//
dummyArray=segArrayOne;
[self.view addSubview:tableDummy];
tableDummy.scrollEnabled=NO;
//[tableDummy release];
[segmentedController addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventValueChanged];
[super viewDidLoad];
}
-(IBAction)buttonPressed:(id)sender{
selectedSegment = [segmentedController selectedSegmentIndex];
switch (selectedSegment) {
case 0:
dummyArray=segArrayOne;
break;
case 1:
dummyArray=segArrayTwo;
break;
case 2:
dummyArray=segArrayThree;
break;
default:
//dummyArray=segArrayOne;
break;
}
NSLog(@"%@",dummyArray);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"%@",dummyArray);
return [dummyArray count];
//return @"";
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [dummyArray objectAtIndex:indexPath.row];
return cell;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请在结尾或情况下调用 [tableDummy reloadData] 。
如果您想重复代码并且不想在默认情况下重新加载数据,
Call [tableDummy reloadData] at the end of
or in the cases if you'd like to duplicate code and don't want to reloadData in a default case.