2012-07-24 60 views
0

我有一個巨大的問題,我不知道如何解決:的.xib文件視圖中創建新實例

myViewController.xib創建的視圖。除了這個視圖控制器的主視圖之外,還有另一個視圖,它被命名爲matchView

在我的主視圖中,我有一個表視圖,它有一個匹配列表。我想在此表格視圖中使用matchView,但是當我撥打addSubview:matchView時,最近的信息填充了此視圖。

如何每次創建此視圖的新實例?

謝謝。

編輯:我解決了我自己的問題,我創建了另一個類,它是matchViewController,然後在cellforrowatindexpath中每次創建它並將其用作[cell addSubview:matchView]。

感謝您的幫助反正..

回答

0

您必須動態地創建爲表中的每一行matchView。

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

    static NSString *CellIdentifier = @"CellIdentifier"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
             reuseIdentifier:CellIdentifier] autorelease]; 
    } 
    UIView *matchView = [[[UIView alloc]init]autorelease]; 
    [matchView setFrame:CGRectMake(0, 0, width_of_your_table, height_of_your_table_cell)]; 
    //add here, in your matchView whatever content you need to be displaied 
    [cell addSubview:matchView]; 
    return cell; 
} 
相關問題