[英].xib file view create new instance
我有一個巨大的問題,我不知道該如何解決:
我在myViewController.xib
創建了一個視圖。 除了該視圖控制器的主視圖之外,還有另一個視圖,名為matchView
。
在我的主視圖中,我有一個帶有匹配列表的表格視圖。 我想在此表視圖中使用matchView
,但是當我調用addSubview:matchView
,最新信息填充了該視圖。
如何每次都創建此視圖的新實例?
謝謝。
編輯:我解決了自己的問題,我創建了另一個類matchmatchController,然后每次在cellforrowatindexpath中創建它,並將其用作[cell addSubview:matchView]。
謝謝您的幫助。
您將必須為表中的每一行動態創建一個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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.