我是一个新的bie并使用段控制器来查看表格,我的表格根据所选的段进行更改...
这里是代码......问题是当我选择任何段时......它没有向我展示任何东西..
- (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;
}
答案 0 :(得分:1)
在
的末尾调用[tableDummy reloadData]-(IBAction)buttonPressed:(id)sender
或者如果你想复制代码并且不希望在默认情况下重新加载数据。