2011-12-23 95 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

相關問題