2011-12-23 8 views
2

私はit.Thereに内容の配列でUItableviewを持って、2つの配列があります、私はボタンのクリックを使用して配列を切り替えたいです。 私のコードはボタンクリックで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である英語のためのボタンがユーザによってクリックされるclick.When、私はこの配列は、ボタンでdelegate.allSelectedVerseEnglishで変更したいことがtableviewcontent(私のテーブルを変更名前はタブです)をdelegate.allSelectedVerseEnglishに設定してください。これはどのように可能ですか。この問題を理解するために手伝ってください。 ありがとうございます。 EDIT:

- (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

一つのことは、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

+0

配列が存在するかどうかチェックしていますか?コンソールに配列を印刷するコードをNSLogで持っていますか? – Hiren

+0

していますか? – Hiren

関連する問題