【发布时间】:2011-09-03 00:16:32
【问题描述】:
所以我知道,如果你们不喜欢我的问题,你们会否决我并降低我的声誉 :( 但我需要学习并且找不到答案,所以在这里我再次冒着我的声誉风险. 现在说到重点。我要做的只是一个带有两个按钮的视图和一个按钮下的表格视图,这个表格视图需要显示一个不同的数组,具体取决于单击的女巫按钮,换句话说,我想要它做的就是单击 button1显示array1,如果我点击button2显示array2,简单!但我无法让它工作。 这是我的代码示例:
- (void)viewDidLoad
{
array1 = [[NSArray arrayWithObjects:
@"A",
@"B",
@"c",
@"D", nil] retain];
array2 = [[NSArray arrayWithObjects:
@"1",
@"2",
@"3",
@"4", nil] retain];
}
- (IBAction)btnPeriodicos:(id)sender {
displayArray = 1;
}
- (IBAction)btnRadios:(id)sender {
displayArray = 2;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (displayArray == 1) {
return [array1 count];
}
if (displayArray == 2) {
return [array2 count];
}
[self.tableView reloadData];
}
- (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];
}
// Configure the cell.
cell.textLabel.textAlignment = UITextAlignmentCenter;
cell.textLabel.textColor = [UIColor blackColor];
if (menuNumberInt == 1) {
cell.textLabel.text = [[periodicoArray objectAtIndex:indexPath.row] retain];
}
if (menuNumberInt == 2) {
cell.textLabel.text = [[radioArray objectAtIndex:indexPath.row] retain];
}
return cell;
}
如果我把 numberOfRowsInSection 和 cell.textLabel.text = [[periodicoArray objectAtIndex:indexPath.row] retain] 的 [array1 count] 代替 if else 语句;该应用程序加载了填充该数组的表格,因此我猜该表格可以工作,但是如何使我的按钮更改表格单元格? 任何帮助是极大的赞赏。 谢谢
【问题讨论】: