1
不工作我是一個新的國際展覽局,並使用分段controlller看錶,我的表更改,根據所選擇的片段......段控制在iphone
這裏是代碼...而問題是,當我選擇任何segment..it沒有顯示我什麼..
- (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;
}
謝謝......它工作.......... – 2011-04-23 14:51:37