我有一个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];
}
my array is delegate。allSelectedVerseMalayalam,我想让这个数组通过委托改变。点击allSelectedVerseEnglish in按钮。当用户点击英语按钮时,它将tableviewcontent(my table names is tab)更改为delegate。这怎么可能呢?请帮我解决这个问题。提前感谢。编辑:
- (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];
}
在tableview 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];
做一件事取一个额外的数组并分配它在源文件中定义。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];
}
使用这个临时数组到表数组