qno*_*oid 16 objective-c ocunit uikit sentestingkit
有没有办法加载原型单元格,以及故事板中定义的任何IBOutlet连接?
更新
我想对单元格(单元的UICollectionViewCell)进行单元测试,因此希望将它加载到UIViewController上下文之外.
实际上,就像您可以从笔尖加载自定义视图一样,指定其文件的所有者并设置其IBOutlet.
flo*_*flo 12
我还没有尝试使用单元测试,但您可以轻松地将自定义UITableViewCell
放入单独的笔尖.
要在视图控制器中使用它,您需要使用tableViews 注册单元格.
UINib *nib = [UINib nibWithNibName:@"ABCNameOfYourNibCell" bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:@"myCustomCell"];
Run Code Online (Sandbox Code Playgroud)
然后使用这样的单元格 cellForRowAtIndexPath:
static NSString *CellIdentifier = @"myCustomCell";
ABCNameOfYourNibCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
Run Code Online (Sandbox Code Playgroud)
为了您的测试目的,您应该能够:
ABCNameOfYourNibCell *testCell =
[[ABCNameOfYourNibCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier:nil];
Run Code Online (Sandbox Code Playgroud)
如果需要测试重用行为,则应在此处设置reuseIdentifier并调用prepareForReuse
该单元.
Ale*_*Cio 11
通常你克里特UITableViewController
或一个UITableView
.比你还应该创建一个UITableViewCell
类.创建UITableViewCell
类后,转到`UIStoryboard,选择单元格:
然后在以下内容中设置UITableViewCell
类Identity Inspector
:
现在添加元素UITableViewCell
并将它们与您的类连接
现在添加CellIdentifier
内部Attributes Inspector
:
没有你的方法UITableViewController
或UIViewController
你的UITableViewDelegate
方法,并像这样打电话给你的单元格(不要忘记在你的顶部#import
的UITableViewCell
课程ViewController
:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"MyIdentifier";
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
[cell.label setText:[NSString stringWithFormat:@"My Cell at Row %ld",
(long)indexPath.row]];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13708 次 |
最近记录: |