如题自定义了一个uitableviewcell如何将其作为cell加入到uitableview谢谢

解决方案 »

  1.   

    - (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。
      

  2.   


    我自定义的cell的名字为ComCell.xib,identifier为ComCell然后如你所说,我的代码    static NSString *CellIdentifier = @"ComCell";
        ComCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[ComCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
        }但是,并没有显示出来?
      

  3.   

    我不太用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,太久没用了,用不来了
      

  4.   

    我的方法:    static NSString *CellIdentifier = @"ComCellIdentifier";
        BOOL nibRegistered = NO;
        if (!nibRegistered) {
            UINib *nib = [UINib nibWithNibName:@"Comcell" bundle:nil];
            [tableView registerNib:nib forCellReuseIdentifier:CellIdentifier];
            nibRegistered = YES;
        }
        
        ComCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];为什么总在  ComCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 句报错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''
      

  5.   

    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 内置路径
      

  6.   


    公司说不用考虑兼容性,所以就不用xib了,直接在storyboard中写但是还想问问,那个NibName是在哪定义?NibName是文件名吗?比方说  MyNib.xib 它的NibName是不是就是 MyNib?
      

  7.   

    ios布局好像比html布局还诡异!我在storyboard中的uitableviewcell中添加了一个view如何设置它的高度?为什么我的设置
    CGRect transmitViewBounds = CGRectMake(0, 0 , 270, 100);
    [cell.subView setBounds:transmitViewBounds];在刚载入时并没有起作用,而是在划出再划入的时候有效果,不过效果却是随机出现在某个cell上请问是怎么回事啊?