当前位置: 代码迷 >> Iphone >> 怎么将自定义的uitableviewcell加入uitableview
  详细解决方案

怎么将自定义的uitableviewcell加入uitableview

热度:16   发布时间:2016-04-25 06:11:26.0
如何将自定义的uitableviewcell加入uitableview
如题

自定义了一个uitableviewcell

如何将其作为cell加入到uitableview

谢谢
------解决方案--------------------
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"merge Second Cell";
    ILSCMMergeSecondCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[ILSCMMergeSecondCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
        
    }
    // Configure the cell...
}

这段代码中ILSCMMergeSecondCell 为自定义的 cell。


------解决方案--------------------
我不太用Xib,块一年了,很难记起来- -!sorry,不过我可以给点意见

我记得原来使用XIB配置 cell 的时候,记得是使用了 NSBundle,获取到cell的XIB文件的路径。  

然后就 用一个方法,好像是这几个中的一个。。。
+ (NSString *)pathForResource:(NSString *)name ofType:(NSString *)ext inDirectory:(NSString *)bundlePath;
+ (NSArray *)pathsForResourcesOfType:(NSString *)ext inDirectory:(NSString *)bundlePath;

- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)ext;


当你获取到了cell 的时候,用来代替 上面的alloc 方法,应该就可以显示出来了


不过,建议还是用代码来实现好了- -!XIB,太久没用了,用不来了

------解决方案--------------------
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/apple/Library/Application Support/iPhone Simulator/6.0/Applications/0019B49A-11B5-4AE0-AACC-3B941E84F309/SnsXib.app> (loaded)' with name 'Comcell''

我不用XIB,直接代码构造UI。。。。背景贴张PNG图片,对着调坐标哇

你上面的错误是说,不能在 默认bundle 读取到 你饿XIB文件。。。NIB 就是 XIB。

bundle 就是你app 内置路径


------解决方案--------------------
对的。就是MyNib 



  相关解决方案