2011-12-23 69 views
2

我有一个UItableview与其中的内容数组。有两个数组,我想通过使用按钮单击切换数组。 我的代码是如何用按钮单击来更改UITableView的内容?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

tab.backgroundColor = [UIColor clearColor]; 
tab.separatorColor = [UIColor clearColor]; 
cell.chapterAndVerse.text = [NSString stringWithFormat:@"%d",indexPath.row+1]; 
cell.chapterAndVerse.font = [UIFont fontWithName:@"Georgia" size:17.0]; 
cell.chapterAndVerse.frame=CGRectMake(0, 10, 30.0, 20.0); 
cell.textLabel.text = [NSString stringWithFormat:@" %@",[delegate.allSelectedVerseMalayalam objectAtIndex:indexPath.row]]; 

cell.textLabel.font = [UIFont fontWithName:@"testfont" size:18]; 
cell.backgroundColor = [UIColor clearColor]; 
} 

我的数组是delegate.allSelectedVerseMalayalam,我想这个数组与delegate.allSelectedVerseEnglish按钮来改变click.When英语的按钮被它改变了tableviewcontent用户点击(我的表名字是选项卡),以delegate.allSelectedVerseEnglish。这是可能的。请帮我找出这个问题。 在此先感谢。 编辑:

在tableview中
- (void)viewDidLoad { 
NSLog(@"%@", delegate.allSelectedVerseMalayalam); 
    tempArray = [[NSMutableArray alloc] init]; 
    [tempArray addObjectsFromArray:delegate.allSelectedVerseMalayalam]; 
    NSLog(@"%@", tempArray); 

    [self.tab reloadData]; 
} 
-(IBAction)_clickbtndefaultlnguageset:(id)sender 
{ 
    [tempArray removeAllObjects]; 
    [tempArray addObjectsFromArray:delegate.allSelectedVerseHindi]; 
    [self.tab reloadData]; 

} 

cell.chapterAndVerse.text = [NSString stringWithFormat:@"%d",indexPath.row+1]; 
cell.chapterAndVerse.font = [UIFont fontWithName:@"Georgia" size:17.0]; 
cell.chapterAndVerse.frame=CGRectMake(0, 10, 30.0, 20.0); 
cell.textLabel.text = [NSString stringWithFormat:@" %@",[tempArray objectAtIndex:indexPath.row]]; 

// cell.textLabel.textColor = [UIColor darkGrayColor]; 
cell.textLabel.font = [UIFont fontWithName:@"testfont" size:18]; 
cell.backgroundColor = [UIColor clearColor]; 

回答

1

做一两件事需要一个额外的阵列和分配它 在源文件中定义prees按钮

后.h文件中

NSMutableArray *tempArray; 

-(void)viewDidLoad{ 
//NSLog(@"%@", your Array); 
tempArray = [[NSMutableArray alloc] init]; 
[tempArray addObjectsFromArray:yourfirstarray]; 
NSLog(@"%@", tempArray); 
[self.tableview reloadData]; 
} 

-(void)pressedBtn{ 
//NSLog(@"%@", your Array); 
[tempArray removeAllObjects]; 
[tempArray addObjectsFromArray:yoursecondArray]; 
[self.tableView reloadData]; 
} 

将此临时数组用于表格数组中

+0

在源文件中定义数组。并首先检查你的委托数组是否存在或不存在?打印数组viewDidLoad – Hiren 2011-12-23 04:45:56

+0

你有没有检查数组是否存在?你有NSLog你的代码在控制台打印数组? – Hiren 2011-12-23 04:54:06

+0

你做到了吗? – Hiren 2011-12-23 05:02:31

相关问题