[英]How to use TableViewCell from xib file on UITableView with no Reusable feature in storyboard
I have this UITableViewCell from a .xib file 我有一个来自.xib文件的UITableViewCell
And I'm using it on a UITableViewCell inside of a storyboard with the following code: 我正在故事板内部的UITableViewCell上使用以下代码:
- (void)viewDidLoad {
[super viewDidLoad];
[requestTableView registerNib:[UINib nibWithNibName:@"RequestAcceptTableViewCell" bundle:nil] forCellReuseIdentifier:@"RequestAcceptCellIdentifier"];
requestTableView.estimatedRowHeight=168;
requestTableView.rowHeight=UITableViewAutomaticDimension;
[requestTableView reloadData];
requestTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [requestArray count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
RequestAcceptTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RequestAcceptCellIdentifier"];
if (cell == nil) {
cell = [[RequestAcceptTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"RequestAcceptCellIdentifier"];
}
return cell;
}
so far this works good: 到目前为止,这很好用:
But I want this to stop reusing UITableViewCells everytime I scroll on my UITableView since I just want to have there a maximum of 5 UITableViewCells inside, I tried with: 但是我希望每次滚动UITableView时都不要再使用UITableViewCells,因为我只想在其中最多容纳5个UITableViewCells,所以我尝试了:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
RequestAcceptTableViewCell = [[RequestAcceptTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:nil];
return cell;
}
and then I get this: 然后我得到这个:
My UITableView has a UITableViewCell with no format, buttons, labels... is there a way to call a UITableViewCell by it's identifier but without reusing it?? 我的UITableView有一个没有格式,按钮,标签的UITableViewCell ...有没有一种方法可以通过其标识符来调用UITableViewCell而不重用它? I mean, keeping it in memory...
我的意思是,将其保存在内存中...
thanks for the support 感谢您的支持
If you do not wish to reuse UITableViewCell, you have to: 如果您不想重复使用UITableViewCell,则必须:
Static Cells
instead of Dynamic Prototypes
. Static Cells
而不是Dynamic Prototypes
。 numberOfRowsInSection
& cellForRowAtIndexPath
) -> IMPORTANT . numberOfRowsInSection
和cellForRowAtIndexPath
)-> 重要 。 IBOutlets
from storyboard to your implementation file. IBOutlets
从情节IBOutlets
板拖放到实现文件中。 Update: 更新:
If you wish to have the Dynamic Prototypes
you could do this: 如果您希望拥有
Dynamic Prototypes
,可以这样做:
Remove this line: RequestAcceptTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RequestAcceptCellIdentifier"]; 删除以下行:RequestAcceptTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@“ RequestAcceptCellIdentifier”];
Add this: 添加:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
RequestAcceptTableViewCell *cell = [[RequestAcceptTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
return cell;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.