首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Iphone >

怎么将自定义的uitableviewcell加入uitableview

2013-01-07 
如何将自定义的uitableviewcell加入uitableview如题自定义了一个uitableviewcell如何将其作为cell加入到ui

如何将自定义的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,太久没用了,用不来了怎么将自定义的uitableviewcell加入uitableview

[解决办法]
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 



热点排行